Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting a .doc to .PDF automatically using VB

Status
Not open for further replies.

kamm

Programmer
Dec 4, 2000
17
GB
I would like to automate the conversion of an MS Word Document to a .pdf document using Visual Basic. Does anyone know how to go about doing this?
Thanks
 
Hi,
If you have Acrobat5, it's easy.

1. Save your .doc as rtf.
2. Load into a VB richtextbox
3. Select PDFwriter as the default printer
3. Print the VB richtextbox
4. The result is a PDF file of your original .doc file.

Hope this helps
 
Well, unfortunately not quite. The VB rich text box does not support all the formatting features used by Word, so it would only be a close approximation.

If you've got Word and Acrobat 5, it would be better to automate Word, and get Word to print to PDFWriter. Something like the following:

Option Explicit

Private Sub Command1_Click()
Dim myWord As Word.Application
Dim myDoc As Word.Document
Dim OriginalPrinter as string

Set myWord = New Word.Application

Set myDoc = myWord.Documents.Open("your_document_name")
OriginalPrinter = myWord.ActivePrinter
myWord.ActivePrinter = "PDFWriter"
myDoc.PrintOut
myWord.ActivePrinter = OriginalPrinter
myDoc.Close (False)
myWord.Quit
Set myWord = Nothing
End Sub



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top