Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Convert xls and doc files to pdf

Posted on 2004-08-10
4
Medium Priority
?
823 Views
Last Modified: 2013-12-25
Hi,

I will convert doc and xls files in pdf format. I need VB6 code to read in a path those files and without open to convert and save them as pdf files. I have acrobat pdf writer5 installed on my pc

Thank you and sorry for my terrible english.
Ivan.
0
Comment
Question by:Ivan_Ita
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
DarkoLord earned 750 total points
ID: 11763913
This is for word, it should be same with excel:

Private objWord As Word.Application
Private objDocument As Word.Document

Private Sub Form_Load()
WritePDF "c:\test.doc"
End Sub

Private Sub WritePDF(FileName As String)
    Dim fName As String
    Dim pName As String
    Dim p As Printer
   
    On Error Resume Next
    Set objWord = GetObject(, "Word.Application")
       
    ' if error then Word wasn't open
    If Err.Number <> 0 Then
        ' open Word
        Set objWord = CreateObject("Word.Application")
    End If
    Err.Clear
   
    On Error GoTo 0
   
    Set objDocument = objWord.Documents.Open(FileName)
   
    ' activate the document
    objDocument.Activate
   
    'Save the default printer name
    pName = Printer.DeviceName
   
    With objWord
        .ActivePrinter = "Adobe PDF"
        'Print the File
        .PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
            wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
            Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, _
            PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
        'Wait until the LOG file is created... this means the PDF has just
        'been created
                   
        'Set the default printer to the original.
        .ActivePrinter = pName
    End With
   
    'Close Word.
     objWord.Quit
   
    ' clean up after our-selves
    Set objWord = Nothing
    Set objDocument = Nothing

End Sub

Darko
0
 

Author Comment

by:Ivan_Ita
ID: 11770021
Hi Darko,

the subroutine is very good but has a little problem: the pdf files must to be generate automatic like a batch job (without any user interactivity). With your function "Acrobat PDF Writer" printer ask for the pdf file name.The function should give to pdfwriter the path+filename and it creates the pdf file:
the file is "c:\test.doc" and the programm generates with the function
WritePDF("c:\test.doc") the file "C:\test.pdf".

Thank you.
Ivan.


0
 
LVL 18

Assisted Solution

by:JR2003
JR2003 earned 750 total points
ID: 11825620
You need the programmable version of cutePDF. This allows you to set the filename in the registry so you don't get the prompt for the file name. There is a charge for this of about $500 though so it's not cheap. You do get royalty free distribution rights though.
0
 

Author Comment

by:Ivan_Ita
ID: 11841612
Hi,

with CutePDF and with the subroutine I have resolved my problem.

Thank you.
Ivan.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question