Showing posts with label vba save word to pdf. Show all posts
Showing posts with label vba save word to pdf. Show all posts

Monday, November 4, 2013

How to save a Word document as a PDF using Visual Basic (VBA)

Set a reference to the Microsoft Word object library.






















Dim wordApp As Word.Application
Dim wordDoc As Word.Document
Dim pdfName As String
Dim curPath as String
curPath = CurrentProject.Path  

Set wordApp = CreateObject("Word.Application")
Set wordDoc = wordApp.Documents.Open(curPath & "\Templates\Some Doc.docx")

pdfName= curPath & "\Some Folder\Converted Doc.pdf"

wordDoc.ExportAsFixedFormat OutputFileName:=pdfName, ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, IncludeDocProps:=True

wordDoc.Close saveChanges:=False