Solved

Convert xls and doc files to pdf

Posted on 2004-08-10
4
820 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

679 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