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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mail merge, print each document to uniquely named pdf and mail to clie

Status
Not open for further replies.

Appcon

Technical User
Oct 23, 2008
1
ZA
Hi all

I'm trying to do a mail merge, save each document with the field data (ID Number.pdf) and then email each document to the corresponding email address in my DB.

The code I am using for the macro looks as follows:

Sub SaveEachDocument()
' SaveEachDocument Macro
'
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim OldPrinter



OldPrinter = Word.ActivePrinter
Word.ActivePrinter = "Adobe PDF"

Application.DisplayAlerts = False
' assign x as the SaveAs Base value
x = "C:\MailMerge\"
With ActiveDocument.MailMerge.DataSource
.ActiveRecord = wdFirstRecord
Do Until .ActiveRecord = .RecordCount
ActiveDocument.SaveAs x & .DataFields("ID_No").Value & "_OfferDocument2009" & ".doc"
'ActivePrinter = "Adobe PDF"

'/// Change the output file name here! ///
sPDFName = .DataFields("ID_No").Value & "_OfferDocument2009" & ".doc"
sPDFPath = x


Set pdfjob = New PDFCreator.clsPDFCreator

With pdfjob
'If .cStart("/NoProcessingAtStartup") = False Then
' MsgBox "Can't initialize PDFCreator.", vbCritical + _
' vbOKOnly, "PrtPDFCreator"
' Exit Sub
'End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With

'Print the document to PDF
ActivePrinter = "Adobe PDF"
ActiveDocument.PrintOut Background:=False, Copies:=1

'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False

'Wait until the PDF file shows up then release the objects
Do Until Dir(sPDFPath & sPDFName) <> ""
DoEvents
Loop
pdfjob.cClose
Set pdfjob = Nothing
.ActiveRecord = wdNextRecord
Loop
End With
Word.ActivePrinter = OldPrinter
ActiveDocument.Close
Application.DisplayAlerts = True
End Sub

However, this code does not execute correctly and is also dependant on having pdf creator installed on the machine.

How do I modify it if using Adobe PDF or activePDF server or different PDF printer?

Would it be better to create an access database to do this?

Regards

Colin
 


Hi,

Please post VBA questions in forum707.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top