0

We have a process where the user saves an email as a .pdf file. I have developed a script that pulls the information for the filename from the email and prompts the user for additional necessary information.

What I can't figure out is how to then have my VBA script select the appropriate Acrobat command in the Ribbon or right-click menu. I've tried executemso, but the msoid is a non-specific "CustomControl". Specifically, the Acrobat add-in adds another tab to the Ribbon called "Acrobat" which then has the option Selected Messages (dropdown) with Create New PDF. Typically, my users just right click the email and choose "Convert to Adobe PDF". A third option would be to programmatically select File | Save as Adobe PDF.

So ideally a user could select an email message and run my VBA macro and that macro would then continue the process to the convert to pdf. Another thought I've had is to somehow watch for the event of creating a pdf and to run the macro and copy the programmatically-created filename to the clipboard.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Acrobat is not required. See [Saving as PDF ...](https://stackoverflow.com/questions/66203210/saving-as-pdf-and-moving-emails-results-in-blank-pdfs) with Outlook VBA. `objDoc.exportasfixedformat OutputFileName:=filePath & fileName & ".pdf", ExportFormat:=17` – niton Aug 10 '22 at 00:57
  • @EugeneAstafiev I have tried the following lines of code: `objDoc = objApp.ActiveInspector.WordEditor` `objDoc.ExportAsFixedFormat2 OutputFileName:=filePath & fileName & ".pdf", WdExportFormat:=17, OpenAfterExport:=0, WdExportOptimizeFor:=0` when I check the objDoc variable after the assignment, it says it is Nothing. – kcfiddle Aug 11 '22 at 16:44
  • Consider posting a new question, about this new topic, with code. – niton Aug 11 '22 at 22:06

1 Answers1

0

There is no trivial way to execute custom ribbon controls from other add-ins. You may consider contacting add-in developers for any public API in the add-in which you could call directly. Also you may take a look at the Accessibility API.

Instead, you can try using the Word object model for saving email as a PDF file on the disk. The Inspector.WordEditor property returns the Microsoft Word Document Object Model of the message being displayed. The Document.ExportAsFixedFormat2 method allows saving a document which represents the message body in PDF or XPS format.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • I have tried the following lines of code: `objDoc = objApp.ActiveInspector.WordEditor` `objDoc.ExportAsFixedFormat2 OutputFileName:=filePath & fileName & ".pdf", WdExportFormat:=17, OpenAfterExport:=0, WdExportOptimizeFor:=0` when I check the objDoc variable after the assignment, it says it is Nothing. – kcfiddle Aug 11 '22 at 16:51
  • What does the [IsWordMail](https://learn.microsoft.com/en-us/office/vba/api/outlook.inspector.iswordmail) method return? – Eugene Astafiev Aug 11 '22 at 17:05
  • `MsgBox (objApp.ActiveInspector.IsWordMail)` displays True. – kcfiddle Aug 12 '22 at 19:22