Hi all,
I am having trouble saving Word documents that I am opening and manipulating through an Excel macro as a .pdf. I've tried several ways and it is not working.
Right now it kind of works, but it asks me to save the changes for each file. I am looping this macro through several files so this is not convenient for me. Thanks for your help!
Dim wdApp As Object
Dim wdDoc As Object
Dim fileloc As String
fileloc = "Macintosh HD:Users:X:Y:Z.docx" 'Replaced folder names with X Y Z for simplicity
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open _
(Filename:=fileloc)
***
*several lines of code where I manipulate the word doc*
***
wdDoc.SaveAs Filename:="Macintosh HD:Users:X:Y:ZZ.docx"
'Saves files as pdf but asks to accept for each file
With Dialogs(wdDialogFileSaveAs)
.Format = wdFormatPDF
.Show
End With
wdDoc.Close savechanges:=False
Set wdDoc = Nothing
wdApp.Quit
Set wdApp = Nothing
I have tried using wdDoc.ExportAsFixedFormat a few different ways and it hasn't worked.
wdDoc.ExportAsFixedFormat OutputFileName:= _
Replace(wdDoc.FullName, ".docx", ".pdf"), _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, Item:= _
wdExportDocumentContent, IncludeDocProps:=False, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
wdDoc.SaveAs2 Filename:="Text.pdf", _
FileFormat:=wdFormatPDF
wdDoc.ExportAsFixedFormat OutputFileName:="Macintosh HD:Users:X:Y:ZZ.pdf", _
ExportFormat:=wdExportFormatPDF
EDIT: I do have the Microsoft Word Object Library enabled in references on excel
Bookmarks