Log in

View Full Version : Converting Word Documents to PDF



jazzyt2u
10-16-2008, 03:08 PM
Hi,
I am trying to automate the process to print word documents to pdf. The coding below works to a point. It's making me click the Save. I don't want to have to babysit this process. Also after I select save I get warnings about margins being outside of the printable range this time making me select yes. These warnings don't appear if I do it manually.

Please help : pray2:


Sub ConvertPdf()
Dim MyFolder As String
Dim oWord As Object
Dim oDoc As Object
Dim NextFile As String
Dim MyFile As String
Set oWord = CreateObject("Word.Application") 'Create an instance of word


MyFolder = InputBox("Please enter or copy and paste the folder path that contains the files for this project." & vbNewLine & _
vbNewLine & "EX: H:\TashaA\Test2\" & vbNewLine & vbNewLine & "Don't forget the last ' \ '")
If Right(MyFolder, 1) <> "\" Then
Do Until Right(MyFolder, 1) = "\"
MyFolder = InputBox("You didn't enter the last '\'." & vbNewLine & vbNewLine & "Please re-enter your folder path EX: H:\TashaA\Test2\")
Loop
End If


NextFile = Dir(MyFolder & "*.doc")

Do While NextFile <> ""

Set oDoc = oWord.Documents.Open(MyFolder & NextFile) 'Open word file
oWord.Visible = True

oWord.ActivePrinter = "Acrobat PDFWriter"
oWord.ActiveDocument.PrintOut
oDoc.Close
NextFile = Dir

Loop
End Sub



Aussiebear: jazzyt2u I have moved this thread from Excel so you can get the assistance you were seeking.

Nelviticus
10-17-2008, 02:05 AM
I had to do something similar a while back and ran into the same problem - the PDFWriter fake printer asks you for a file name for every document. I couldn't find a way around this because Adobe's tools are virtually impossible to control with VBA so I ended up using something called Universal Document Converter (http://www.print-driver.com/).

This is another fake printer which can save your documents in a range of formats including PDF and which you can configure with various settings, including using the same file name as the document you're sending. It isn't free but if you're going to be doing the same task in the future it might be worth the spend.

Or you could search for a free alternative, there are plenty of free PDF converters out there and maybe there's one that will do the job for you.

Regards