Solved

Convert xls and doc files to pdf

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

Title # Comments Views Activity
VB error "Type mismatch" 2 59
Notepad++ how to remove delimiter : from beggning of the line? 3 111
VB6 ListBox Question 4 48
checkbox to hide entire section 10 40
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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.
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…

792 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