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:
- Once you have enabled the Developer tab, select the tab and press the Macros button.
- In the Macros in list, click the template or document in which you want to store the macro.
- In the Macro name box, type a name for the macro.
- 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.
nWdExportCreateOption
- a custom enumeration extending MicrosoftWdExportCreateBookmarks
enumeration withwdExportCreateHeadingAndWordBookmarks
option.sOutputPath
- a output folder where the PDF file should be saved.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.bReferToNamedDestinations
- after converting PDF bookmarks to named destinations, you can set existing bookmarks to use newly created named destinationsnWdExportOptimizeFor
- 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.sResponseSet 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:
- Select the tab where you'd like to add the macro button to.
- Click the File button next to the Home tab and choose Options. Here, select the section "Customize Ribbon".
or
Right click any tab and choose "Customize the Ribbon".
You'll find the current tab already highlighted and selected. - 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. - From the dropdown list "Choose commands from:" select: Macros.
The list below will now show you all your macros. - Select the macro that you wish to create a button for and press the Add >> button.
- 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.
- Unlike a toolbar button, you cannot assign your ALT+key combination via letters.
- Close the Editor Options dialog to return to your item window and use your button.
FAQ About PDF Destinator for Word
Evaluations
Purchasing
- Comapany name
- Address
- Contact person
- VAT (tax) number
- Confirm the product/quantity you want to buy
- 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)