Saving Word doc as PDF from excel macro

hlg0035

New Member
Joined
Sep 8, 2014
Messages
13
Hi all-

Having some trouble converting a word document into a PDF from my excel macro. This is the error message: invalid procedure call or argument.

Here is my code for saving the word document, then saving it as a PDF.

Set WrdApp = CreateObject("Word.Application")
WrdApp.Visible = True
Set WrdDoc = WrdApp.Documents.Open("C:\Users\" & UserID & "\Desktop\Quantien Evaluation Template 9.5.docx")

'SAVE THE WORD DOCUMENT AS A SEPARATE FILE
WrdDoc.SaveAs2 Filename:= _
"C:\Users\" & UserID & "\Desktop\ " & CustomerName & " " & City & " " & State & " " & CustomerNumber & " " & "Quantien Evaluation Agreement" & " " & Month(Now()) & "." & Day(Now()) & "." & Year(Now()) & ".doc" _
, FileFormat:=wdFormatXMLDocumentMacroEnabled, LockComments:=False, _
Password:="", AddToRecentFiles:=True, WritePassword:="", _
ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, CompatibilityMode:=14

'saving as a pdf....
WrdDoc.ExportAsFixedFormat OutputFileName:= _
"C:\Users\" & UserID & "\Desktop\ " & CustomerName & " " & City & " " & State & " " & CustomerNumber & " " & "Quantien Evaluation Agreement" & " " & Month(Now()) & "." & Day(Now()) & "." & Year(Now()) & ".pdf" _
, ExportFormat:=wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Same problem as your other post. Replace the following Word constants with their value:

wdFormatXMLDocumentMacroEnabled 13
wdExportFormatPDF 17
wdExportOptimizeForPrint 0
wdExportAllDocument 0
wdExportDocumentContent 0
wdExportCreateNoBookmarks 0
 
Upvote 0
Worked perfectly :) Thanks!

Same problem as your other post. Replace the following Word constants with their value:

wdFormatXMLDocumentMacroEnabled 13
wdExportFormatPDF 17
wdExportOptimizeForPrint 0
wdExportAllDocument 0
wdExportDocumentContent 0
wdExportCreateNoBookmarks 0
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,730
Members
448,987
Latest member
marion_davis

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