Save Email as .msg File with Code

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.
 
D

Dmitry Streblechenko

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
-
 
P

Peter Hibbs

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.
 
P

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.
 
D

Dmitry Streblechenko

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
-
 
P

Peter Hibbs

Yes, I already discovered that and have added some code to check this.

Thanks again.

Peter Hibbs.
 
Joined
Nov 8, 2012
Messages
1
Reaction score
0
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top