Solved

Convert xls and doc files to pdf

Posted on 2004-08-10
4
817 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
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
DarkoLord earned 250 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 250 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

832 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