answersLogoWhite

0


Best Answer

The following script demonstrates how to save Outlook messages automatically to a file as new emails arrive to your inbox.

Major parts of the code has been fetched from forums and edited by me.

As end result, you will get all your incoming messages in the following folder structure on your harddrive.

Example:

c:\data\emails

201008

20100801_FirstEmailInAugust.msg

20100801_SomeOtherEmail.msg

20100802_SomeEmailAugust2nd.msg

201009

20100801_FirstEmailInSeptember.msg

Advantages:

- File search can be used to find emails

- No more corrupted PST files (if you have LOTS of emails)

The script has been tested for Microsoft Outlook 2003.

You need to perform following steps:

1. Add the script code

- Open "Tools->Macro->Visual" Basic Editor

- Enter the code as in the end-of the post

2. Add reference to \Windows\System32\Scrrun.dll

- Use "Tools->References..." in Visual Basic Editor

3. Optional: Create a digital certificate

- This is needed if you have medium/high security settings

- In windows, push Start->Programs->Microsoft Office Tools

- Select "Digital Certificate for VBA projects"

- Give some name to your certificate

4. Optional: Sign your code

- This is needed if you have medium/high security settings

- Open "Tools->Digital Signature" in Visual Basic Editor

5. Add outlook rule to process message

- Open "Tools->Rules and Alerts" in Outlook

- Create a new rule (the way you wish)

- As rule action, use "run a script" and select "SaveAsMsg"

The code follows:

-----------------------------------------------------------------------

Sub SaveAsMsg(MyMail As MailItem)

' requires reference to Microsoft Scripting Runtime

' \Windows\System32\Scrrun.dll

' For Coders - see also: http://www.outlookcode.com/article.aspx?id=52

Dim fso As FileSystemObject

Dim strSubject As String

Dim strSaveName As String

Dim blnOverwrite As Boolean

Dim strFolderPath As String

Dim looper As Integer

Dim strID As String

Dim olNS As Outlook.NameSpace

Dim oMail As Outlook.MailItem

' ### For coders: see http://www.outlookcode.com/article.aspx?id=52 for

explanation

strID = MyMail.EntryID

Set olNS = Application.GetNamespace("MAPI")

Set oMail = olNS.GetItemFromID(strID)

' ### USER OPTIONS ###

blnOverwrite = False ' False = don't overwrite, True = do overwrite

strFolderPath = "C:\RAAN\Data\Emails" ' path to target folder

strFolderPath = strFolderPath & Format(Now, " yyyymm") & "" ' Adds year/month

subfolder

If EnsureFolderExistence(strFolderPath) <> "PATH DOES NOT EXIST" Then

strSubject = CleanFileName(oMail.Subject)

strSaveName = Format(Now, " yyyymmdd") & "_" & strSubject & ".msg"

Set fso = CreateObject("Scripting.FileSystemObject")

If blnOverwrite = False Then

looper = 0

Do While fso.FileExists(strFolderPath & strSaveName)

looper = looper + 1

strSaveName = Format(Now, " yyyymmdd") & "_" & strSubject & "_" &

looper & ".msg"

Loop

Else

If fso.FileExists(strFolderPath & strSaveName) Then

fso.DeleteFile strFolderPath & strSaveName

End If

End If

oMail.SaveAs strFolderPath & strSaveName, olMSG

End If

Set oMail = Nothing

Set olNS = Nothing

Set fso = Nothing

End Sub

Function EnsureFolderExistence(strPath) As String

Dim fso As FileSystemObject

On Error Resume Next

Set fso = CreateObject("Scripting.FileSystemObject")

If Not fso.FolderExists(strPath) Then

fso.CreateFolder strPath

If Err <> 0 Then

EnsureFolderExistence = "PATH DOES NOT EXIST"

End If

End If

Set fso = Nothing

End Function

Function CleanFileName(strText As String) As String

Dim strStripChars As String

Dim intLen As Integer

Dim i As Integer

strStripChars = "/\[]:=," & Chr(34)

intLen = Len(strStripChars)

strText = Trim(strText)

For i = 1 To intLen

strText = Replace(strText, Mid(strStripChars, i, 1), "")

Next

CleanFileName = strText

End Function

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How to save outlook messages automatically to a file as they arrive?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the extension of Outlook Express?

Some of the important file extensions of Outlook and Outlook Express are mentioned as below :Microsoft Outlook :Outlook Data File (.pst)Offline Folder File (.ost)Personal Address Book (.pab)Offline Address Books (.oab)Messages (.msg, htm, .rtf)Stationary (.htm)Rules (.rwz)Outlook Express :Outlook Express data file (.dbx)Email Files (.eml)Email messages as text files (.txt)Address book (.wab)Contact information (.vcard)Internet Account files (.iaf)


How do you get an eml file to play on Windows media player?

A .eml file is not a media file. .eml files are typically saved e-mail messages from Microsoft Outlook Express. The e-mail may have a media file attached to it, however, in order to save the attachment and play it, you need to open the .eml file in Outlook Express.


Is the outlook pst file where all current emails are held?

Yes, Microsoft Outlook stores all email messages in a single .pst file on your local hard drive.Resource: Location of Outlook varies from version to versionIn MS Outlook 2013: C:\Program Files\Microsoft Office\Office15In MS Outlook 2010: C:\Program Files\Microsoft Office\Office14


What do you do when you can't open email?

Microsoft Outlook creates a PST file, while you configure an account in Outlook. The PST stores copies of messages, calendar, notes, tasks, contacts and other items. PST file may get corrupted because of many reasons, in that case, you would be unable to open Outlook. The reasons could be Virus, improper outlook shutdowns, corruption in header files, pst file has reached maximum size limit etc. In that case you can use outlook utility, named Inbox repair tool to fix your pst file.


How do you import from outlook express to outlook 2007?

Use your windows mail in windows vista, import normally like you would with the old outlook express&lt; file- import &gt; messages, and so on, then go to outlook 2007 and import from windows mail from there! other ! there is no other way!


How can you save Outlook Express messages?

Depends on how you'd like to export them. Do you want to back them up or do you want to convert them to some other format? Use import and export feature of the outlook express , or in simple words try to copy all the dbx file of the outlook express ( for example sent .dbx , inbox.dbx , etc )


How do you increase size of pst file in outlook?

How to Increase Outlook PST File Size


Can you open outlook pst files in Microsoft for mac?

Yes, we can access Outlook PST file in Outlook 2011 but first you need to convert PST File into EML File.


Which file has pst extension?

Microsoft Outlook stores all of a user's personal information (such as email messages, contacts, calendar events, tasks, and journal entries) in a single file that ends with a .pst extension. Often this file is named Outlook.pst.


Does outlook 2003 backup.pst work with outlook 2002?

Outlook 2003 .pst file is not compatible with previous versions of Outlook like 2002, 2002 etc. It can not be directly opened in previous versions of Outlook. To open an Outlook 2003 .pst backup file into 2002, make a new .pst file into 97-2002 format and then import all the data from backup .pst file into this file. Now you can open the .pst file into Outlook 2002. regards Jane


How do you move all your messages and settings from MS Outlook on one computer to another?

The good thing about MS Outlook (not Outlook Express) is that it holds all the messages, folders, and hierarchy information in the single .pst file (PST stands for Personal Storage Table). Almost all you need to do is to locate the .pst file on your old machine and copy it to the new one. The steps below show the process: Install Outlook on your new machine and set it up. Find the location of the Outlook.pst file on the new machine. You can use Windows search function from the Start menu. You can also open MS Outlook, click File one the top dropdown menu, click Open, and then choose Outlook Data File. Then click on the arrow next to Outlook and remember or write down the exact location of the Outlook.pst file. Very frequently it may be: C:\Documents and Settings\Local Settings\Application Data\Microsoft\Outlook.pst. Determine the location of the old .pst file on the old machine. Save your rules to a file if you use Inbox Rules if you use them. Shut down Outlook on both old and new machines. Copy the old Outlook.pst from the old machine to the new, replacing the new Outlook.pst on the new machine. Import Inbox Rules if you use them. Do not use MS Outlook on the old machine or delete the account settings from the old machine. You obviously want all the new messages to be saved only in the newly set up Outlook.pst file.


How do you copy Outlook Contacts for use on another PC?

You have to export the Outlook contacts for use. You can export to make a file and then import that file on other outlook.