PaulGodley
New Member
- Joined
- Jun 18, 2008
- Messages
- 13
Hi Guys,
I want to run a macro from Excel to use an Excel list as the merge fields in a Word document.
Each individual word document then needs to be saved as a PDF.
I've used the attached code from inside Word, and it works fine,
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"C:\Users\Paul\Desktop\Doc2pdfmacro.pdf", ExportFormat:=wdExportFormatPDF
But, I can't get it to work in Excel.
I have created an Object for Word, (AppWD).
See below
Do While Len(FName) > 0
If appWD Is Nothing Then
Set appWD = CreateObject("Word.Application") ' New Word.Application
End If
appWD.Documents.Open Filename:=DesktopPath & "FormToMerge.docx"
appWD.Visible = True
With appWD.ActiveDocument.MailMerge
.OpenDataSource Name:=DesktopPath & "Separated Workbooks\" & FName, SQLStatement:="SELECT * FROM [listing]"
'.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute Pause:=False
End With
Can anyone help me please?
Thanks
Paul
I want to run a macro from Excel to use an Excel list as the merge fields in a Word document.
Each individual word document then needs to be saved as a PDF.
I've used the attached code from inside Word, and it works fine,
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"C:\Users\Paul\Desktop\Doc2pdfmacro.pdf", ExportFormat:=wdExportFormatPDF
But, I can't get it to work in Excel.
I have created an Object for Word, (AppWD).
See below
Do While Len(FName) > 0
If appWD Is Nothing Then
Set appWD = CreateObject("Word.Application") ' New Word.Application
End If
appWD.Documents.Open Filename:=DesktopPath & "FormToMerge.docx"
appWD.Visible = True
With appWD.ActiveDocument.MailMerge
.OpenDataSource Name:=DesktopPath & "Separated Workbooks\" & FName, SQLStatement:="SELECT * FROM [listing]"
'.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute Pause:=False
End With
Can anyone help me please?
Thanks
Paul