Outlook mails backup

vilkas

New Member
Joined
Oct 12, 2013
Messages
14
Hi,

Could someone help me to understanding why the code bolow do not backups reply or forward emails? i works on received or send emails only...


Code:
Sub backup_selectioProject()
Dim OL As Application
Dim NmeSpace As NameSpace
Dim FNme As String
Dim dtDate As Date
'Dim omail As Outlook.MailItem
Set OL = CreateObject("Outlook.Application")
Set NmeSpace = OL.GetNamespace("MAPI")
Set Inbx = NmeSpace.GetDefaultFolder(olFolderInbox)
Set Fldr = Application.ActiveExplorer.CurrentFolder
DirName = "Z:\Departments-WUIB\"
For Each itm In ActiveExplorer.Selection
     SubTxt = itm.Subject
    'SubTxt = CleanString(SubTxt) 'removes characters that cannot be part of filename
    dtDate = itm.ReceivedTime
    'Set omail = objItem
    'dtDate = omail.ReceivedTime
     FNme = DirName & SubTxt & "_" & Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, _
vbUseSystem) & ".MSG"
    'sName = Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, _
vbUseSystem) & Format(dtDate, "-hhnnss", _
vbUseSystemDayOfWeek, vbUseSystem) & "-" & sName & ".msg"
'sPath = enviro & "\Documents\"
    
    
     If itm.Class = olMail Then
       
        itm.SaveAs FNme, olMSG
    End If
     
    Next
End Sub

Thanks in advance!
 
Last edited by a moderator:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
No, I mean what is the actual subject of the email?
 
Upvote 0
You can't create a file with a colon in its name - try adding code to replace that.
 
Upvote 0
Ou, I forgot about that, you were right. I will try to use the code to eliminate the colon and other unnecessary symbols. Thanks a lot!
 
Upvote 0
Ou, I forgot about that, you were right. I will try to use the code to eliminate the colon and other unnecessary symbols. Thanks a lot!
Something like this
Rich (BB code):
' Usage: eSub = ValidForFilename(msg.Subject)
Function ValidForFilename(ByVal Txt) As String
  Dim x
  For Each x In Split("? "" / \ < > * | :")
    Txt = Replace(Txt, x, "_")
  Next
  ValidForFilename = Txt
End Function
 
Upvote 0

Forum statistics

Threads
1,225,681
Messages
6,186,411
Members
453,352
Latest member
OrionF

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top