You can do this with Word 2007, provided you have the PDF plug-in installed
with the following macro.
Earlier Word versions do not have the ability to save to PDF and require a
third party application to do so.
If your third party application is not Acrobat, you may have to acknowledge
a confirmation prompt for each document conversion.
You would have to replace the code segment
..SaveAs FileName:=strNewPath & _
vShortName(0) & _
".pdf", _
FileFormat:=wdFormatPDF
With an option to print to the PDF driver. For Acrobat you would need:
Dim sPrinter As String
With Dialogs(wdDialogFilePrintSetup)
sPrinter = .Printer
.Printer = "Adobe PDF"
.DoNotSetAsSysDefault = True
.Execute
oDoc.PrintOut
.Printer = sPrinter
.Execute
End With
and set the acrobat printer driver to direct the output to a particular
folder. You will find some information on the driver setting at
http://www.gmayor.com/individual_merge_letters.htm
The original documents are unaffected.
Sub BatchProcess()
Dim strFilename As String
Dim strPath As String
Dim strNewPath As String
Dim vShortName As Variant
Dim oDoc As Document
'Set the path to receive the documents
strNewPath = "d:\My Documents\Test\Merge\"
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select folder and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User", , _
"List Folder Contents"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" _
Then strPath = strPath + "\"
End With
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
If Left(strPath, 1) = Chr(34) Then
strPath = Mid(strPath, 2, Len(strPath) - 2)
End If
strFilename = Dir$(strPath & "*.doc")
While Len(strFilename) <> 0
Set oDoc = Documents.Open(strPath & strFilename)
With oDoc
vShortName = Split(strFilename, ".")
.SaveAs FileName:=strNewPath & _
vShortName(0) & _
".htm", _
FileFormat:=wdFormatFilteredHTML
.SaveAs FileName:=strNewPath & _
vShortName(0) & _
".pdf", _
FileFormat:=wdFormatPDF
.Close SaveChanges:=wdDoNotSaveChanges
End With
strFilename = Dir$()
Wend
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>