Save Email as .msg File with Code

  • Thread starter Thread starter Peter Hibbs
  • Start date Start date
P

Peter Hibbs

This is what I do at the moment :-

Open Outlook (2003)
Download my emails
Select an email
Click File -> Save As...
Switch to Outlook Message Format (*.msg)
Locate my 'save messages' folder and click Save to save the email as a
..msg file in the selected folder.

This is what I would like to do :-

Open Outlook (2003)
Download my emails
Select an email
Click a button on the tool-bar which would automatically save the
selected email as a .msg file in a preselected folder.

What code would I need to do that. I have written code stored in the
VbaProject.OTM file before so that would be my first choice. I have
also seen Web sites that recommend using an Add-In file (.dll) but I
have not done that before so that would not be my preference. I have
created a button on the tool-bar with code so I am familiar with the
procedure for that part.

The other problem I have is that I will be testing this with OL2003
but I also need it to work on OL2007, hopefully that will be possible
using the same code (no idea at the moment on how to add buttons to a
ribbon but will cross that bridge when I get to it, if I ever do).

Peter Hibbs.
 
Something like

for each Msg in Application.ActiveExplorer.Selection
Msg.SaveAs("c:\temp\Filename.msg", olMsg)
next

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
Dmitry,

I tried this :-


Public Sub SaveMessage()

Dim Msg As Variant

For Each Msg In Application.ActiveExplorer.Selection
msg.SaveAs("c:\temp\Filename.msg", olMsg) '<--red text
Next

End Sub


but the middle line of the For-Next shows up in red. Is there anything
else I need to do?

Peter Hibbs.
 
Dmitry,

OK, I think I sorted it. Used this -


Dim Msg As Variant

For Each Msg In Application.ActiveExplorer.Selection
Msg.SaveAs "c:\temp\" & Msg & ".msg", olMSG
Next


Thanks again.

Peter Hibbs.
 
The line
"c:\temp\" & Msg & ".msg",
woudl read the default property from teh message, which happens to be
Subject::
"c:\temp\" & Msg.Subject & ".msg",

You need to ensure that the file name does not contain invalid chracters,
such as ":", "\", etc.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
Yes, I already discovered that and have added some code to check this.

Thanks again.

Peter Hibbs.
 
The eFiler Outlook add-in solves exactly this problem, saving emails as msg files in file system folders and giving a powerful search tool so emails can be found and used as if still in Outlook.

Just search for "eFiler", read more about it and download the free 30 day trial.
 
Back
Top