I have a document that I want to automate the conversion to PDF format. When I run the macros below manually Word does the conversion ok, but if I run the macro test() (with Word open and no documents open), word just hangs and I have to force quit the application. This happens on Windows 7 and Windows 8 but does NOT happen on XP. Also tested with Word 2007, Word 2010 and Word 2013, all do the same thing.
I think the issue is the document has nested tables in it? Doesn't make sense if I can do it manually or run the 2 macros independently. It just freezes when I run them back to back with the test() macro.
Note: I can step through the test macro and it will work if I go slow enough, if I hit F8 too fast it will freeze. I tried to put a delay in between the steps but it still freezes.
Sub openfile()
Documents.Open FileName:="c:\temp\test.docx", ConfirmConversions _
:=False, ReadOnly:=True, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
End Sub
Sub export()
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"C:\temp\test.pdf", ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent, _
IncludeDocProps:=False, KeepIRM:=True, CreateBookmarks:= _
wdExportCreateNoBookmarks, DocStructureTags:=False, BitmapMissingFonts:= _
True, UseISO19005_1:=False
ActiveDocument.Close
End Sub
Sub test()
openfile
export
End Sub