Word 2007 & Acrobat 9: Macro to generate PDF

P

Paul Moloney

I'm trying to create a macro which does some checks on a document (for
example, refreshes all fields and checks for broken x-refs by searching for
the text "Error!") before PDFing it.

Does anyone know what VBA will perform the same task performed by clicking
the Acrobat-->Create PDF option?

Also, if anyone know of any similar macros that perform error-checking on
Word document, please let me know,

Thanks,

P.
 
G

Graham Mayor

To create a PDF from Word using the Acrobat add-in by vba, you could use
something like the following. You will need to set a reference to the
AdobePDFMakerForOffice object library in the vba editor. Or you could use
the Office 2007 PDF plug-in and save the document as PDF.

Option Explicit
Sub ConvertToPDF()
Dim pdfname, i, a
Dim pmkr As AdobePDFMakerForOffice.PDFMaker
Dim stng As AdobePDFMakerForOffice.ISettings

With ActiveDocument
'The document must be saved - so save it!
.Save
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 = Left(.name, InStrRev(.name, ".")) & "pdf"
' delete PDF file if it already exists
If Dir(pdfname) <> "" Then Kill pdfname
pmkr.GetCurrentConversionSettings stng
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
pmkr.CreatePDFEx stng, 0 'perform conversion
If Dir(pdfname) = "" Then ' see if conversion failed
MsgBox "Could not create " & pdfname, vbOKOnly, "Conversion failed"
End If
End With
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

I forgot the error search

Dim oField As Field
For Each oField In ActiveDocument.Fields
If InStr(1, oField.Result, "Error!") Then
oField.Select
MsgBox oField.Code
Exit Sub
End If
Next oField

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top