A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

VBA code to extract selected emails and save to C drive



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 22nd 11, 09:58 PM
MrMartino MrMartino is offline
Junior Member
 
First recorded activity at Outlookbanter: Jun 2011
Posts: 1
Default VBA code to extract selected emails and save to C drive

Hi all,

I'm trying to piece together code that allows me to highlight several emails in outlook (2003 or before) to then click a macro which will create a folder on my desktop before saving the selected emails to the created folder.

I am totally untrained and new to Outlook VBA (I've more self taught experience in Word and Excel) but have used the code below together with the MkDir reference to initially create the folder to save to. This manages to save the first email selected into the folder but doesn't save any more of the other emails selected.

Perhaps it's something to do with selection or not having a loop? Like I said I'm new to this. Could someone out there help????

Public Sub SaveEMailasMsg()
MkDir "C:\Documents and Settings\Desktop\Extracted Emails - Created by Outlook Macro"
Dim msg As MailItem
Const strPath As String = "C:\Documents and Settings\Desktop\Extracted Emails - Created by Outlook Macro\" ' set as desired
If Inspectors.Count 0 Then
' Assume the "active" inspector has the message to be saved
Set msg = ActiveInspector.CurrentItem
Else
' Assume the first selected item is the message to be saved
Set msg = ActiveExplorer.Selection(1)
End If
' The above will fail if we try to set msg to a non-MailItem item
' Cleanse illegal characters from subject... :/|*?"
Dim strFileName As String, intCounter As Integer
' Specific substititions
strFileName = Trim(Replace(msg.Subject, ":", ";"))
strFileName = Replace(strFileName, "", "(")
strFileName = Replace(strFileName, "", ")")
strFileName = Replace(strFileName, """", "'")
' Catch-all for the rest
For intCounter = 1 To Len(strFileName)
If InStr(1, "/|*?", Mid(strFileName, intCounter, 1)) 0 Then
Mid(strFileName, intCounter, 1) = "-"
End If
Next
strFileName = Format(msg.SentOn, "yymmdd_") & strFileName & Format(msg.SentOn, "_hhmmss") & ".msg"
msg.SaveAs Path:=strPath & strFileName, Type:=olMSG
Set msg = Nothing
End Sub

Thanks in advance.
Ads
 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
save certain emails from inbox to network drive with a macro Herb Segal Outlook and VBA 2 November 2nd 09 04:17 PM
Newbie- is this possible? (code to save attachments from server to network drive, without opening email locally) ker_01 Outlook and VBA 3 October 3rd 08 03:33 PM
VBA to set selected emails to "Do not Autoarchive this item" TommoUK Outlook and VBA 1 April 23rd 08 06:54 AM
Please help - VBA to save email to drive [email protected] Outlook and VBA 5 July 4th 07 03:34 AM
Save emails by sender to local drive folder Albert Outlook - General Queries 1 January 12th 06 04:42 PM


All times are GMT +1. The time now is 04:35 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.