WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: domvalle@comcast.net on November 05, 2019, 06:20:38 PM

Title: Word save as PDF
Post by: domvalle@comcast.net on November 05, 2019, 06:20:38 PM
Trying to get this right... ExportAsFixedFormat does not work...

file = "C:\temp\testdom.docx"
App = ObjectOpen("Word.Application")
Docs = App.Documents
Doc = Docs.Open(file)
Doc.ExportAsFixedFormat(::OutputFileName="C:\temp\testdom.pdf", ExportFormat=wdExportFormatPDF, OpenAfterExport=False)
Doc.Close()
App.Quit()

ObjectClose(Doc)
ObjectClose(Docs)
ObjectClose(App)

pause("Word Convert", "Complete")

exit

Actual Word Macro shows this:
Sub Macro1()
'
' Macro1 Macro
'
'
    ActiveDocument.ExportAsFixedFormat OutputFileName:="C:\temp\testdom.pdf", _
        ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
        wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
        Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
        CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
        BitmapMissingFonts:=True, UseISO19005_1:=False
    ChangeFileOpenDirectory "C:\temp\"
End Sub

any suggestions?, thanks!
Title: Re: Word save as PDF
Post by: stanl on November 06, 2019, 02:34:36 AM
Just a quick guess but...


has wdExportFormatPDF been previously assigned in your script

might want to use @FALSE
Title: Re: Word save as PDF
Post by: domvalle@comcast.net on November 06, 2019, 03:17:29 AM
you are correct, I have not.
I don't know what wdExportFormatPDF should be.
I will try to find out...
Title: Re: Word save as PDF
Post by: domvalle@comcast.net on November 06, 2019, 03:52:12 AM
ok, looks like wdExportFormatPDF = 17
but still fails, must be some syntax issue?
Title: Re: Word save as PDF
Post by: domvalle@comcast.net on November 06, 2019, 03:57:40 AM
Oh, actually getting an 'Assignment not legal here. (Use == for equality testing) here
-->Doc.ExportAsFixedFormat(OutputFileName="C:\temp\testdom.pdf", ExportFormat=wdExportFormatPDF, OpenAfterExport=TRUE)
...hmmm
Title: Re: Word save as PDF
Post by: domvalle@comcast.net on November 06, 2019, 04:29:58 AM
OK, this line worked to save!
Doc.SaveAs("C:\temp\testdom.pdf",wdExportFormatPDF)
duh!