ich habe ein Excel Datei it Makros in deren Verlauf ich eine Word Formatvorlage fülle. Soweit klappt das alles auch gut.
Sub Test()
Dim wrdApp
Dim wrdDoc
Dim Pfad As String
Pfad = ThisWorkbook.Path & "\Vorlagen\Vorlage Gutschrift.docx"
On Error GoTo ErrorExit
Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Open(Pfad)
wrdApp.Visible = False
wrdDoc.FormFields("Text1").Result = Tabelle2.Cells(Zeile, 4)
wrdDoc.FormFields("Text2").Result = Tabelle2.Cells(Zeile, 9)
wrdDoc.FormFields("Text3").Result = Tabelle2.Cells(Zeile, 10) & " " & Tabelle2.Cells(Zeile, _
11)
wrdDoc.FormFields("Text4").Result = Tabelle2.Cells(Zeile, 12) & " " & Tabelle2.Cells(Zeile, _
13)
wrdDoc.FormFields("Text5").Result = Tabelle2.Cells(Zeile, 8)
wrdDoc.FormFields("Text6").Result = TextBox2.Text
wrdDoc.FormFields("Text7").Result = TextBox3.Text
wrdDoc.FormFields("Text8").Result = TextBox1.Text
Pfad = ThisWorkbook.Path & "\Dokumente\" & TextBox1.Text & ".pdf"
wrdDoc.Save
wrdDoc.Close
ErrorExit:
wrdApp.Quit
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub
Nun würde ich gerne noch das Word Dokument über die Funktion Speicher unter ... Als pdf freigeben direkt als pdf speichern.
Für ein Excel-Blatt funktioniert das mit
Tabelle10.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Pfad _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
Für ein Word-Objekt bringt das allerdings einen Fehler.
Über den Word Makro-Aufzeichner habe ich gesehen, dass der Word Befehl etwas verändert aussieht.
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"C:\Users\Tim IJsselstein\Desktop\Vorlage Gutschrift.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
Diesen Befehl verweigert mir aber auch mein Excel vba. Der Kackpunkt ist das ExportFormat:= _
wdExportFormatPDF das er nicht erkennt/akzeptiert.
Jemand eine Idee?
Danke und Gruß
Tim