Save a PDF from a Word doc via XL VBA

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
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,224,521
Messages
6,179,278
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top