Click here to Skip to main content
15,886,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I'd like to code an outlook VBA macro that allows me to save .tif mail attachments in .pdf Since no such Outlook option exists, I first save the .tif as it is and then I am launching "Windows Photo Viewer" to open it, then I choose the Print option and select the "Microsoft to PDF" printer in the printers list.
This way, I can even split a multi-page .tif into single-page pdf's (very important for what I need to do).

What I have tried:

I am trying to use:

VB
Public Function StartDoc(attachmntPath)

  Dim Shex as object
  Set Shex = CreateObject("Shell.Application") 
  Shex.ShellExecute attachmntPath, "", "", "print" 

  'Wait for user to click the PRINT button
  'Take the lead again


End function


ShellExecute opens the .tif using the application that I choose to associate with the file extension .tif
'Print as a verb allows me to skip the first screen of "Windows Photo Viewer" and brings me directly to the "Print Pictures" screen from where I can select the "Microsoft to PDF" printer and specify the page range if needed.

Is there a way to pause the macro in order to wait for when the user clicks on the PRINT button located on the "Print Picture" screen ?

Please note that I managed to use API's to find the "Print Pictures" window's handle as well as the "PRINT" button's handle.

Last thing, If someone knows an alternative way to get to the same results in Outlook directly, this will be equally highly appreciated.

Thanks a lot in advance
Posted
Updated 1-Sep-21 0:14am
v2
Comments
Maciej Los 1-Sep-21 3:16am    
Does:
1) MS Word/Excel
and/or
2) pdf printer
is installed on your OS?

Do you want to print only images or entire maile message?
Member 15343067 1-Sep-21 3:56am    
Hi, I have both MS Word/Excel. I don't need to print the entire email only the images
CHill60 1-Sep-21 3:33am    
Maciej Los 1-Sep-21 4:03am    
Good point!
Member 15343067 1-Sep-21 4:17am    
Hi,
Thanks for the tip.
I read that article before but my understanding was that, there, it is explained how to wait for the end of the shelled process. In my case, I'd like to catch a user action (click on the "Print" button) while the shelled application ("Windows Photo Viewer") is still opened (not ended or closed).

1 solution

AFAIK there is no way to capture that button click as you are shelling the application, not interacting via an API.
Quote:
Last thing, If someone knows an alternative way to get to the same results in Outlook directly, this will be equally highly appreciated.
I would probably save the attachments into a Microsoft Word document and then Save As or Print To PDF from there.

Found these examples:
How to Quickly Export All Image Attachments of an Outlook Email to a Word Document - Data Recovery Blog[^]
How to save a Microsoft Word document as a PDF file[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900