Save Current Email as HTML Through VBA .

Hello.

I use the following code in MS Word to save my current document as a .pdf.

Sub Save_to_PDF()
'' Save_to_PDF Macro
  With Dialogs(wdDialogFileSaveAs)
        .Format = wdFormatPDF
        .Show
    End With
    End Sub

I want to do something similar with MS Outlook. I want to save outlook messages as a .html file. Currently, to do this, I open the message I want to save, File-->Save As --> Save as Type=HTML --> Save.

I want to have a Macro that I can attach to my Quick Access Toolbar that does it for me. I can not figure it out. I tried using this source to help, https://msdn.microsoft.com/en-us/vba/outlook-vba/articles/mailitem-saveas-method-outlook, but it only got me more confused.

Moved from: Office / Outlook / Windows 10 / Office 2016

Duplicate Post? - if so please ignore my answer!

Hi Marek, see if the sub below is what you need . . .

Sub saveAsHTML(myItem As Outlook.MailItem)
Dim m As MailItem
Set m = CreateItem(olMailItem)
m.SaveAs "c:\temp\aMail.html", olhtml
End Sub
___________________________________________________________________

Power to the Developer!

MSI GV72 - 17.3", i7-8750H (Hex Core), 32GB DDR4, 4GB GeForce GTX 1050 Ti, 256GB NVMe M2, 2TB HDD

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

Thank you. But I am missing something. I have the code input into VBA,

But how do I activate it? It does not show up as a Macro in the developer tab.

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

Zarek, have a read on this page, it might help you . . .

https://www.experts-exchange.com/questions/2806...
___________________________________________________________________

Power to the Developer!

MSI GV72 - 17.3", i7-8750H (Hex Core), 32GB DDR4, 4GB GeForce GTX 1050 Ti, 256GB NVMe M2, 2TB HDD

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

After taking ALT+F11, did you insert a standard module by right clicking on Microsoft Outlook Objects?

If it is done, it will be available in Macro Window which you can invoke through ALT+F8 or by clicking Macros in Developer tab.
Best regards
Vijay Verma

Timezone: UTC+05:30, PST+12:30
Availability Hours (UTC) : 05:00 AM - 05:00 PM

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

Mr. E For Excel. I did not "insert a standard module by right clicking on Microsoft Outlook Objects". Can you walk me through this?

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

1. Open Outlook
2. ALT+F11 to open VBE
3. On left side, your will notice Project 1 or something like that
4. Right click on this > Insert > Module
5. Paste your code into this Module and Save
Best regards
Vijay Verma

Timezone: UTC+05:30, PST+12:30
Availability Hours (UTC) : 05:00 AM - 05:00 PM

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

Okay. Thank you. I am getting there. I am using this code: Sub OpenAndSave()     Const SAVE_TO_FOLDER = "C:\Users\MyName\Desktop\"     Dim olkMsg As Outlook.MailItem, intCount As Integer     intCount = 1     For Each olkMsg In Outlook.ActiveExplorer.Selection           olkMsg.SaveAs SAVE_TO_FOLDER & "Message #" & intCount & " " & ".html"          intCount = intCount + 1     Next     Set olkMsg = Nothing End Sub The problem is that when I save it to the html, and open the html, I get a whole bunch of jibberish. See small excerpt below. The actual text is there, but its further down. "`WgaXôgerQa9ocufre\0Waodîu0ôùWôÏ€gdfÿÉ`Òñ apUâôÿnaóyrö´" I am guessing that Outlook is trying to convert pictures into text. Which is why I am getting this

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

 
 

Question Info


Last updated April 29, 2020 Views 2,758 Applies to: