Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88087

Saving Word document as PDF using Excel VBA

$
0
0

This is related to converting a Word document to PDF format.

I get an error in my Excel VBA code.

Run-time error "5": Invalid procedure call or argument

Saving into a Word document works

objWord.ActiveDocument.SaveAs PathName & NewFileName & ".docx"

The below runs but it creates a PDF document which is very big in size.

objWord.ActiveDocument.SaveAs2 Filename:=PathName & NewFileName & ".pdf", _ 
  FileFormat:=wdFormatPDF

I recorded a macro in Word to save the file as PDF and modified the generated code as per below.

objWord.ActiveDocument.ExportAsFixedFormat OutputFileName:= _
  PathName & NewFileName & ".pdf", _
  ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
  wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
  Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
  CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
  BitmapMissingFonts:=True, UseISO19005_1:=False

I am using Excel VBA to do a Mailmerge using Word document and it is working fine and able to save individual documents in Word format but I need to save it in PDF format.


Viewing all articles
Browse latest Browse all 88087

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>