Saving a Word document as PDF from en Excel macro
Hello NG
I have an Excel macro, that creates a number single Word-documents (not mail merge), based on data from en Excel spreadsheet, using bookmarks in the Word document. I want to save the documents as PDF files, but so far with no success.
My code startes with:
On Error Resume Next
Set Wdapp = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set Wdapp = CreateObject("Word.Application")
End If
<followed by a lot of of transfer from Excel to Word stuff and then I try to save as PDF with:
doknavn = ldir & "\" & a & ".pdf"
Wdapp.ChangeFileOpenDirectory ldir
Wdapp.ActiveDocument.ExportAsFixedFormat OutputFileName:= _
doknavn, ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
wdExportAllDocument, Item:=wdExportDocumentContent, _
IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:= _
wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _
True, UseISO19005_1:=False
but nothing happens. Apparently no pdf files are created. If i save as Word documents in stead, like in this test
Wdapp.ActiveDocument.SaveAs Filename:="C:\test\" & Navn & number & ".doc"
it Works perfectly. If I run the same code in a Word-document, it works as well. Can't you automate exports to pdf?
Anyone?
Jan
|