PDA

View Full Version : outlook saveas macro



nw3
07-04-2006, 06:48 PM
Hi

Anybody knows how to write macros in outlook to save all messages in the inbox as .msg files? I have found an example in the help, but it's for open messages only. It does not work on multiple open messages either.

Thanks for the help.

NW3

Parry
07-04-2006, 08:46 PM
Hi heres an example. This will create msg files for all the messages within the currently selected folder in Outlook into a folder called C:\Testing. The destination folder (ie C:\testing) must be valid so change this to an existing folder before running.


Sub Example()
Dim i As Long

With Outlook.ActiveExplorer.CurrentFolder

For i = 1 To .Items.Count
.Items(i).SaveAs "C:\Testing\" & .Items(i) & ".msg", olMSG
Next i

End With

End Sub

nw3
07-04-2006, 09:14 PM
Thanks.

The code is much simpler.

However punctuations can be a pain. I will modify to remove the punctuations <>?/|"* etc so outlook can save.

Thanks again.

NW3

Parry
07-04-2006, 09:33 PM
You might also have to add subfolders as if theres 2 messages with the same subject name an error is going to occur. Parent.Name will give you the folder of the current item.

Outlook.ActiveExplorer.CurrentFolder.Items(i).Pare nt.Name

There should be a way to get each folder then loop through each item in the folder but its not readily appearent. I dont know the Outlook object model so its guesswork.