Microsoft Word Post Macro to PDF

If you are a VB developer and have questions about using our products from VB, here is the place to post them.
Post Reply
mike1174
Posts: 7
Joined: Tue Nov 08 2005

Microsoft Word Post Macro to PDF

Post by mike1174 »

Hello, can someone post an example on how to convert a doc to a pdf in a word post macro and save it to the same directory and name the word document is in?
mike1174
Posts: 7
Joined: Tue Nov 08 2005

Post by mike1174 »

I came up with the following code.. just have 2 questions. Is this the fastest possible, and does anyone know how I can reference the open documents name without specifying the "c:\test.pdf" and the "c:\PDF_Test.doc"?

Public Sub ConvertToPDF()
Dim pdf As New CDIntfEx.CDIntfEx
Dim doc As Document
Dim strLicenseTo, strActivationCode As String

Set doc = Documents.Open(FileName:="c:\PDF_Test.doc")

' Printer initialization (the printer should be installed on the system)
pdf.DriverInit "Amyuni PDF Converter"

pdf.EnablePrinter strLicenseTo, strActivationCode
' ***** Printing a Word document to PDF *****

' Set file name options
pdf.FileNameOptionsEx = 1 + 2
pdf.DefaultFileName = "c:\test.pdf"

' Enable the printer before each printout
pdf.EnablePrinter strLicenseTo, strActivationCode

doc.Application.ActivePrinter = "Amyuni PDF Converter"

' Print the Word document (concatenated to the first pdf file)
doc.PrintOut Background:=False

' Reset 0ptions to zero
pdf.FileNameOptions = 0

pdf.DriverEnd

Set pdf = Nothing

End Sub
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Hello,

As far as I know, this is the fastest way to open a Word document and print it to the PDF Printer.

Another alternative would be to use BatchConvert() function to batch print all Word documents in a given directory lets say, this is not faster because MS Word will be opened before printing too.

Concerning the file name. If you wish to specify the file name yourself you need to explicitely specify it as you did in you code, otherwise you may choose to give the PDF file the same name as the original document, in this case you do not add 2 to your call of FileNameOptions you add 'Overwrite without notification' or 'Add Id' or 'Add date time' options. For further information please check page 22 of the manual "Common Driver Interface 250.pdf".

Then instead of using pdf.DefaultFileName you will use pdf.DefaultDirectory to specify the output directory.

Hope this helps.
mike1174
Posts: 7
Joined: Tue Nov 08 2005

Common Driver Interface Control

Post by mike1174 »

Everytime I try to add the common driver interface control as a component to a VB project, VB gives me an error that says "Name conflicts with existing module, project, or object library". The project, or modules are not named Common Driver Interface Control.

Do you know why this is happening?
mike1174
Posts: 7
Joined: Tue Nov 08 2005

Post by mike1174 »

Also, the references that I have in use now in the project are:

Visual basic for applications
Visual basic runtime objects and procedures
Visual basic objects and procedures
Microsoft ActiveX Data Objects 2.5 library
Microsoft Word 8.0 object library
OLE Automation
Microsoft scripting runtime
mike1174
Posts: 7
Joined: Tue Nov 08 2005

Post by mike1174 »

I just got off the phone with tech support and they had me open the vb vpb file in notepadand remove the reference to the common driver interface. I then open up vb, and was able to add it through the menu (project->references)...
Post Reply