I have an Excel linked Word document with VBA code in Excel. At the end of the code sequence I want to save the Word document in a specified folder and with file format "Word document" (aka doc or docx) and afterwards as PDF document.
I am trying to do so via, but the output file I get does not have "any" format. Also specifying the file format in the filename does not help.
Additionally, trying to export the file as PDF does not work either (invalid procedure ...)
Any suggestions?
Best, Franzi
Sub WordErstellen(rechnungsnummer As Variant, firma As Variant, name As Variant, datum As Variant)
Dim WordApp As Object
Dim dateiname, pfad As Variant
path_word = "C:\mypath\Word\"
path_pdf = "C:\mypath\PDF\"
myfilename = rechnungsnummer & "_" & firma & "_" & name & "_" & datum
Set WordApp = CreateObject("Word.Application")
Set doc = WordApp.Documents.Add("C:\mypath\mytemplate.docm")
WordApp.Visible = True
doc.Activate
'Save
doc.SaveAs2 Filename:=path_word & myfilename, FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False, CompatibilityMode:=15
doc.ExportAsFixedFormat OutputFileName:=path_pdf & myfilename, _
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
End Sub
I am trying to do so via, but the output file I get does not have "any" format. Also specifying the file format in the filename does not help.
Additionally, trying to export the file as PDF does not work either (invalid procedure ...)
Try:
doc.SaveAs2 path_word & myfilename & ".docx", 12, False, "", True
doc.SaveAs2 path_word & myfilename & ".pdf", 17, False, "", True
PS: you don't need:
doc.Activate
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.