Microsoft Word Post Macro to PDF
Microsoft Word Post Macro to PDF
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?
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
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
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.
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.
Common Driver Interface Control
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?
Do you know why this is happening?