D
DaveLett
I'm posting a question that was raised in a different forum. We use a tool
that can publish to Word, and the tool allows you to create AfterPublish Word
routines. The OP is looking to convert a published Word document to PDF. The
OP found and modified the following routine. I have commented to show what
was working and what wasn't working. The OP is using Word 2003 and Acrobat 7.
How can we remove the two MsgBox lines and prevent Word from crashing?
Sub ConvertToPDFWithLinks()
' ----------------------------------------------------
' ConvertToPDFWithLinks - convert the current document
' to a PDF file, in the same folder as the document
' ----------------------------------------------------
Dim pdfname, i, a
Dim pmkr As AdobePDFMakerForOffice.PDFMaker
Dim stng As AdobePDFMakerForOffice.ISettings
If Not ActiveDocument.Saved Then
MsgBox "You must save the document before converting it to PDF",
vbOKOnly, ""
Exit Sub
End If
Set pmkr = Nothing ' locate PDFMaker object
For Each a In Application.COMAddIns
If InStr(UCase(a.Description), "PDFMAKER") > 0 Then
Set pmkr = a.Object
Exit For
End If
Next
If pmkr Is Nothing Then
MsgBox "Cannot Find PDFMaker add-in", vbOKOnly, ""
Exit Sub
End If
pdfname = ActiveDocument.FullName ' construct output name
i = InStrRev(pdfname, ".")
pdfname = IIf(i = 0, pdfname, Left(pdfname, i - 1)) & ".pdf"
' delete PDF file if it exists
If Dir(pdfname) <> "" Then Kill pdfname
'''The following line is from the original routine
'''pmkr.GetCurrentConversionSettings stng
'''The OP changed the line above to the one following
'''The OP says that Word does not raise an error when
'''executing the following line but does raise an error
'''when executing the previous line
Set stng = pmkr.GetCurrentConversionSettings()
stng.AddBookmarks = True ' make desired settings
stng.AddLinks = True
stng.AddTags = False
stng.ConvertAllPages = True
stng.CreateFootnoteLinks = True
stng.CreateXrefLinks = True
stng.OutputPDFFileName = pdfname
stng.PromptForPDFFilename = False
stng.ShouldShowProgressDialog = True
stng.ViewPDFFile = False
'''The OP says that they added this MsgBox b/c, without it,
'''Word crashes
MsgBox "Starting Conversion", vbOKOnly, "Starting Conversion"
'''The following line is from the original routine
'''pmkr.CreatePDFEx stng, 0 'perform conversion
'''The OP changed the line above to the one following
'''The OP says that Word does not raise an error when
'''executing the following line but does raise an error
'''when executing the previous line; notice that the only
'''change is commenting out the second parameter
pmkr.CreatePDFEx stng ', 0 perform conversion
'''The OP says that they added this MsgBox b/c, without it,
'''Word crashes
MsgBox "Conversion complete", vbOKOnly, "Conversion done"
If Dir(pdfname) = "" Then ' see if conversion failed
MsgBox "Could not create " & pdfname, vbOKOnly, "Conversion failed"
End If
End Sub
Thanks
Dave
that can publish to Word, and the tool allows you to create AfterPublish Word
routines. The OP is looking to convert a published Word document to PDF. The
OP found and modified the following routine. I have commented to show what
was working and what wasn't working. The OP is using Word 2003 and Acrobat 7.
How can we remove the two MsgBox lines and prevent Word from crashing?
Sub ConvertToPDFWithLinks()
' ----------------------------------------------------
' ConvertToPDFWithLinks - convert the current document
' to a PDF file, in the same folder as the document
' ----------------------------------------------------
Dim pdfname, i, a
Dim pmkr As AdobePDFMakerForOffice.PDFMaker
Dim stng As AdobePDFMakerForOffice.ISettings
If Not ActiveDocument.Saved Then
MsgBox "You must save the document before converting it to PDF",
vbOKOnly, ""
Exit Sub
End If
Set pmkr = Nothing ' locate PDFMaker object
For Each a In Application.COMAddIns
If InStr(UCase(a.Description), "PDFMAKER") > 0 Then
Set pmkr = a.Object
Exit For
End If
Next
If pmkr Is Nothing Then
MsgBox "Cannot Find PDFMaker add-in", vbOKOnly, ""
Exit Sub
End If
pdfname = ActiveDocument.FullName ' construct output name
i = InStrRev(pdfname, ".")
pdfname = IIf(i = 0, pdfname, Left(pdfname, i - 1)) & ".pdf"
' delete PDF file if it exists
If Dir(pdfname) <> "" Then Kill pdfname
'''The following line is from the original routine
'''pmkr.GetCurrentConversionSettings stng
'''The OP changed the line above to the one following
'''The OP says that Word does not raise an error when
'''executing the following line but does raise an error
'''when executing the previous line
Set stng = pmkr.GetCurrentConversionSettings()
stng.AddBookmarks = True ' make desired settings
stng.AddLinks = True
stng.AddTags = False
stng.ConvertAllPages = True
stng.CreateFootnoteLinks = True
stng.CreateXrefLinks = True
stng.OutputPDFFileName = pdfname
stng.PromptForPDFFilename = False
stng.ShouldShowProgressDialog = True
stng.ViewPDFFile = False
'''The OP says that they added this MsgBox b/c, without it,
'''Word crashes
MsgBox "Starting Conversion", vbOKOnly, "Starting Conversion"
'''The following line is from the original routine
'''pmkr.CreatePDFEx stng, 0 'perform conversion
'''The OP changed the line above to the one following
'''The OP says that Word does not raise an error when
'''executing the following line but does raise an error
'''when executing the previous line; notice that the only
'''change is commenting out the second parameter
pmkr.CreatePDFEx stng ', 0 perform conversion
'''The OP says that they added this MsgBox b/c, without it,
'''Word crashes
MsgBox "Conversion complete", vbOKOnly, "Conversion done"
If Dir(pdfname) = "" Then ' see if conversion failed
MsgBox "Could not create " & pdfname, vbOKOnly, "Conversion failed"
End If
End Sub
Thanks
Dave