save word documents in a folder as pdf

P

peter.cawley

I was hoping that somebody out there could help me?

I have a limited knowledge of excel VBA and I'm attempting to write a
macro in word, which will read all of the files within a directory and
save them to an array and then convert all of the word documents in a
pdf format. I've tried to do this by recording a macro but I haven't
had any luck.

I'm working with Word 2003 and Adobe acrobat 7.0

If anybody can point me in the write direction I'd appreciate it

Thanks in advance
 
G

Graham Mayor

The following will print all the documents in a folder to PDF using the
current settings in the Adobe print driver.

Sub PrintFolderContents()
On Error GoTo err_FolderContents
Dim DocList As String
Dim DocDir As String
Dim sPrinter As String
Documents.Close SaveChanges:=wdPromptToSaveChanges
sPrinter = ActivePrinter
ActivePrinter = "Adobe PDF"
Application.ScreenUpdating = False
DocDir = InputBox("Change Document Path if necessary", _
"Folder Information ", CurDir)
If DocDir = "" Then
Exit Sub
End If
DocList = Dir(DocDir & "\*.doc", vbNormal)
Do While DocList <> ""
Documents.Open DocList
ActiveDocument.PrintOut
ActiveDocument.Close wdDoNotSaveChanges
DocList = Dir
Loop
Application.ScreenUpdating = True
ActivePrinter = sPrinter
Exit Sub
err_FolderContents:
MsgBox Err.Description
Exit Sub
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

peter.cawley

Hi Graham,

Thanks for the quick response, I've tried the code below and whilst I
think it assumes that I need to manually open the files, which isn't a
big problem, it does come up with an error message of "There is a
printer error". When I've debugged the code the message comes up
straight the printer Adobe PDF printer is assigned...would have any
ideas on this?

Many thanks,

Pete.
 
G

Graham Mayor

While I have revised the code slightly (below) to allow you to select the
folder, you need to check your PDF printer driver settings.
There is no facility to 'save as' PDF. You have to output to the Adobe print
driver and for that the documents must be opened.
From the Adobe PDF 'printer' driver properties > Adobe PDF Settings >
uncheck
View Adobe PDF Results
and
Add document information
Provide an output folder in place of 'prompt for filename'


Sub PrintFolderContentsToPDF()
On Error GoTo err_FolderContents
Dim FirstLoop As Boolean
Dim DocList As String
Dim DocDir As String
Dim sPrinter As String

With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
DocDir = .Directory
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With

If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If

sPrinter = ActivePrinter
ActivePrinter = "Adobe PDF"
Application.ScreenUpdating = False

FirstLoop = True

If Left(DocDir, 1) = Chr(34) Then
DocDir = Mid(DocDir, 2, Len(DocDir) - 2)
End If

DocList = Dir$(DocDir & "*.doc")
Do While DocList <> ""
Documents.Open DocList
ActiveDocument.PrintOut
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
DocList = Dir$()
FirstLoop = False
Loop
Application.ScreenUpdating = True
ActivePrinter = sPrinter
Exit Sub
err_FolderContents:
MsgBox Err.Description
Exit Sub
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

peter.cawley

Hi Graham,

Sorry to keep pestering...

I've tried to find the Adobe PDF printer driver properties but I'm not
having much luck!!! I've looked in the print settings both within Word
and Adobe and the only printer driver that I can find is the network
printer (start menu>settings>printer and faxes>) and a PDF-XChange 3.0
but that doesn't have the options that you have listed below.

Am I looking in the wrong place?

Thanks,

Pete.
 
G

Graham Mayor

You said you had Acrobat 7 and the macro was based on that premise.
I don't know anything about PDF-XChange 3.0 but if that's the name of its
driver, change that for Adobe PDF in the macro. It may prompt you for a name
for each file, unless it has an option not to do so.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jonathan West

I was hoping that somebody out there could help me?

I have a limited knowledge of excel VBA and I'm attempting to write a
macro in word, which will read all of the files within a directory and
save them to an array and then convert all of the word documents in a
pdf format. I've tried to do this by recording a macro but I haven't
had any luck.

I'm working with Word 2003 and Adobe acrobat 7.0

Would that be Adobe Acrobat *Reader* 7.0 or the full commercial version of
the product?


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
M

Malcolm Smith

*From:* (e-mail address removed)
*Date:* 9 Jan 2007 01:47:26 -0800

I was hoping that somebody out there could help me?

I have a limited knowledge of excel VBA and I'm attempting to write a
macro in word, which will read all of the files within a directory and
save them to an array and then convert all of the word documents in a
pdf format. I've tried to do this by recording a macro but I haven't
had any luck.

I'm working with Word 2003 and Adobe acrobat 7.0

If anybody can point me in the write direction I'd appreciate it

Thanks in advance


Don't record a macro, write some VBA.

What you need to do is to go and switch to your Acrobat printer and then
print each document in turn to that printer and then return to your
original printer.

- Malc
 
P

peter.cawley

Apologies for any confusion, whilst I do have Adobe Acrobat reader 7.0,
I do have PFD XChange 3.0 as part of MS Word. I didn't realise that
this was my printer driver
 
P

peter.cawley

Graham,

I changed the name of the printer to "PDF-XChange 3.0" and it's worked
a treat...

Many thanks!!!
 
G

Graham Mayor

That's a relief ;)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top