Solved

Convert xls and doc files to pdf

Posted on 2004-08-10
4
815 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Hi,

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

Thank you.
Ivan.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now