Excecuting PDF Destinator COM Add-In from VBA

Use Macros to Automate Tasks in Microsoft Word

PDF Destinator for Word Add-In Professional version allows to automate tasks using VBA within an Microsoft Office environment. Instead of running the export wizard every time, take the time to create a macro for the most common PDF export tasks.

PDF Destinator COM Add-In export functionality is exposed to VBA. Excecuting PDF Destinator COM Add-In from VBA, the export wizard is hidden and the add-in module is managed programmatically. First, create a macro using Visual Basic for Applications:

  1. Once you have enabled the Developer tab, select the tab and press the Macros button.
  2. In the Macros in list, click the template or document in which you want to store the macro.
  3. In the Macro name box, type a name for the macro.
  4. Click Create to open the Visual Basic Editor.


After typing a name for the macro you want to create and clicking the Create button, Word switches you to the VBA editor and creates a skeleton of a macro for you. VBA requires knowledge of basic programming concepts. Here is a sample VBA script you can use to create your own PDF export tasks. Define your input parameters before executing the subroutine.

  1. nWdExportCreateOption - a custom enumeration extending Microsoft WdExportCreateBookmarks enumeration with wdExportCreateHeadingAndWordBookmarks option.
  2. sOutputPath - a output folder where the PDF file should be saved.
  3. bValidatePdfBookmarks - PDF Destinator for Word Add-In validates exported PDF bookmarks according to the requirements specified by Abobe. Custom character replacement mappings should be created and changed by export wizard.
  4. bReferToNamedDestinations - after converting PDF bookmarks to named destinations, you can set existing bookmarks to use newly created named destinations
  5. nWdExportOptimizeFor - specifies the resolution and quality of the exported document.


Ready-to-run code sample

You can run a procedure interactively in the VBA environment by using the Immediate window (Debug window). This window may already be displayed at the bottom of the IDE. If not, you can open it using View -> Immediate Window.

' PDF Destinator for Word Add-In Professional
' © 2013-2020 Grifir Software OU, http://pdfw.grifir.com
' This sample code demonstrates how to write a VBA macro in
' Microsoft Word and use PDF Destinator for Word COM Add-In
' module programmatically in your VBA code.
' System Requirements:
' (1) Any version of Windows (32-bit or 64-bit) that can run
'     Office 2007, 2010 or Office 2013 (32-bit or 64-bit).
' (2) Microsoft Office since 2007
' (3) Microsoft .NET Framework 4.5 installed.
' (4) PDF Destinator for Word Professional 1.3
' Usage: call Destinator_Main()

Enum WdExportCreateBookmarks
    ' A custom enumeration extending Microsoft WdExportCreateBookmarks
    ' enumeration with wdExportCreateHeadingAndWordBookmarks option.
    ' http://msdn.microsoft.com/en-us/library/bb243310(v=office.12).aspx
    wdExportCreateNoBookmarks = 0
    wdExportCreateHeadingBookmarks = 1
    wdExportCreateWordBookmarks = 2
    wdExportCreateHeadingAndWordBookmarks = 3
End Enum

Enum WdExportOptimizeFor
    ' A standard Microsoft enumeration
    ' http://msdn.microsoft.com/en-us/library/bb243313%28v=office.12%29.aspx
    wdExportOptimizeForPrint = 0
    wdExportOptimizeForOnScreen = 1
End Enum

Type TParams
    ' A user defined type (UDT) used as parameter
    nWdExportCreateOption       As WdExportCreateBookmarks
    sOutputPath                 As String
    bValidatePdfBookmarks       As Boolean
    bReferToNamedDestinations   As Boolean
    nWdExportOptimizeFor        As WdExportOptimizeFor
    bBitmapMissingFonts         As Boolean
    bUseISO19005_1              As Boolean
    bExportWdBookmarksAsNd      As Boolean
    sPdfBookmarkFindWhat        As String
    sPdfBookmarkReplaceWith     As String
    sResponse                   As String
End Type

Sub Destinator_Main()
    ' Destinator_Main
    ' This subroutine declares PDF Destinator for Word COM Add-In
    ' module, defines input parameters, executes a private worker
    ' function and returns a result info
    Dim objAddin          As COMAddIn
    Dim objAdxModule      As Object
    Dim udtTParams        As TParams
    Set objAddin = Application.COMAddIns.Item("PDFDestinatorForWord.AddinModule")
    Set objAdxModule = objAddin.Object

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Set your input parameters before executing the subroutine ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' See WdExportCreateBookmarks enum description udtTParams.nWdExportCreateOption = WdExportCreateBookmarks.wdExportCreateHeadingBookmarks ' A output folder where the PDF file should be saved. udtTParams.sOutputPath = "C:\tmp" ' This option converts Word bookmarks to PDF named destinations. ' Set it FALSE if you want to create only PDF bookmarks. udtTParams.bExportWdBookmarksAsNd = True ' If you want to change PDF bookmarks BEFORE converting it to named destinations, ' uncomment the following two lines. sPdfBookmarkFindWhat also accepts regular expression. ' For example, setting udtTParams.sPdfBookmarkFindWhat = "^[\d.]*\s*", and ' udtTParams.sPdfBookmarkReplaceWith = "", the heading numbers are removed from the PDF document. udtTParams.sPdfBookmarkFindWhat = "" udtTParams.sPdfBookmarkReplaceWith = "" ' After converting PDF bookmarks to named destinations, you can ' set existing bookmarks to use newly created named destinations. udtTParams.bReferToNamedDestinations = False ' PDF Destinator for Word validates exported PDF bookmarks according ' to the requirements specified by Abobe. Custom character replacement ' maps should be created and changed by Graphical User Interface. udtTParams.bValidatePdfBookmarks = True ' Specifies the resolution and quality of the exported document udtTParams.nWdExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForOnScreen ' True to include a bitmap of the text; false to reference the ' text font. Set this parameter to true when font licenses do not permit ' a font to be embedded in the PDF file. udtTParams.bBitmapMissingFonts = True ' True to limit PDF usage to the PDF subset standardized as ISO 19005-1. udtTParams.bUseISO19005_1 = False ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Now executing the converter ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Call ExportPdf(objAdxModule, udtTParams) ' Debug.Print udtTParams.sResponse MsgBox udtTParams.sResponse
Set objAddin = Nothing End Sub Private Function ExportPdf(objAdxModule As Object, udtTParams As TParams) As String ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' ExportPdf ' This function executes the COM Add-In exposed method ' Parameters: ' ------------------------------------------------------------- ' objAdxModule PDFDestinatorForWord.AddinModule defined ' and instantiated in the calling code ' udtTParams A user defined type (UDT) used as parameter ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' udtTParams.sResponse = objAdxModule.ExportPdfAction( _ udtTParams.nWdExportCreateOption, _ udtTParams.sOutputPath, _ udtTParams.bValidatePdfBookmarks, _ udtTParams.bReferToNamedDestinations, _ udtTParams.nWdExportOptimizeFor, _ udtTParams.bBitmapMissingFonts, _ udtTParams.bUseISO19005_1, _ udtTParams.bExportWdBookmarksAsNd, _ udtTParams.sPdfBookmarkFindWhat, _ udtTParams.sPdfBookmarkReplaceWith ) End Function

Create a button on the Ribbon

After creating your macro, you can assign a custom button on the Ribbon or a custom button on the Quick Access toolbar and then run PDF Destinator COM Add-in with your macro by clicking that custom button. To assign a macro to a custom group on a custom Ribbon tab, you follow these steps:


  1. Select the tab where you'd like to add the macro button to.
  2. Click the File button next to the Home tab and choose Options. Here, select the section "Customize Ribbon".
    Right click any tab and choose "Customize the Ribbon".
    You'll find the current tab already highlighted and selected.
  3. Create a New Group or even a New Tab to place your custom button in. You cannot add your button to an existing group.
    You can use the Rename… button to give your group and/or tab a nice name.
  4. From the dropdown list "Choose commands from:" select: Macros.
    The list below will now show you all your macros.
  5. Select the macro that you wish to create a button for and press the Add >> button.
  6. To modify the name and icon press the Modify… button.
    • Unlike a toolbar button, you cannot assign your ALT+key combination via letters.
      When you close the Editor Options dialog and press and release the ALT button on your keyboard, you'll a letter above the tabs. Type the letters above your tab and then you'll see letters above the the commands on the commands. Type the letter above your macro to activate your macro.
    • Unlike a toolbar button, you cannot paste your own icon or freely edit it. However, the icon list is longer and the icons are of a higher quality when compared to previous versions of Outlook.
  7. Close the Editor Options dialog to return to your item window and use your button.

FAQ About PDF Destinator for Word


Yes. We provide free evaluation limited-function version of our software. You can try out the functions and performance of our product before purchasing it.

The software is delivered electronically (via HTTP download).

It is imperative that you remove the trial version when installing the shipping version. Please do not attempt to install the shipping version over the trial version. To remove the trial version of PDF Destinator for Word Add-in, use the "Add/Remove Programs" Control Panel to remove the trial version.


We accept credit cards (including MasterCard, Visa or American Express) via Paypal payment processing. Shopping is safer and easier with PayPal. You do not need to have an account to purchase, and all major credit cards are accepted. Your payment is transferred securely through PayPal. Your credit card and bank account numbers are never shared with online stores, and you're 100% protected. See more: Payments by PayPal.

If you are a business and would like to order by an purchase order (PO) or you need an invoice, please send us the following information:
  • Comapany name
  • Address
  • Contact person
  • VAT (tax) number
  • Confirm the product/quantity you want to buy

A substantial 30% academic discount is offered to qualifying academic institutions.

The academic discount is available to students, faculty and staff of eligible education institutions. You should send a proof of eligibility to get the software. Email your proof of educational status to: info@grifir.com.
  • Your name
  • Address (city, state, country)
  • Name of school / University
  • Your department of study (computer science, chemistry, humanities)
  • Your status (student, faculty, research stuff/assistant, administration)

License Info

The basic functionality is the same across the editions. The standard version lacks the VBA (Visual Basic for Applications) support. The another difference is the number of installations you are allowed with each license. If licensee has purchased a Single User License, one copy of the software may be used by one single user. A Multi User License allows installing software on maximum three (3) workstations, used by three (3) different users. If licensee is using the software under the control of a Site License, licensee may install the software on an unlinited number of computers at licensee's organization at a single location ("Site"). Enterprise Edition buyers get PDF Destinator for Adobe Acrobat® in addition.

End-User license agreement is available here.

Support and Documentation

Technical support can be contacted via e-mail at info@grifir.com. Grifir Software doesn't provide technical support by phone.

If you are getting the specific error message "An Unexpected Error Occurred", this means there may be an internal problem with the system. You could find more information from the help file how to report an error.

Download the user guide and product documentation for PDF Destinator for Word Add-in here or access online documentation. After installing the software, you can find the user guide under the Windows start menu.