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)
That code should process all mail items in the currently selected folder. Are your replies and forwards in that folder?
 
Upvote 0
Hi,

it works on selected emails only(For Each itm In ActiveExplorer.Selection) sorry for messy code...
 
Upvote 0
OK - so what is the problem exactly? If you have selected replies or forwards, they should be processed unless something is altering their class from the default olMail type.
 
Upvote 0
I've adjusted a code. Cleared all unnecessary lines. I found that problem appears to be from subject lines, so i have deleted them also. What additional code do I need to a add in order to print the email subject too?

Code:
Sub backup_selectioProject1()
Dim FNme As String
Dim dtDate As Date
Dim msg As Object
 
DirName = "Z:\Departments\"
For Each msg In Application.ActiveExplorer.Selection
dtDate = msg.ReceivedTime
     
     FNme = DirName & "_" & Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, _
vbUseSystem) & ".MSG"
    
    
     If TypeName(msg) = "MailItem" Then
       msg.SaveAs FNme, olMSG
       
       
    End If
     
    Next
End Sub
 
Upvote 0
msg.Subject should be correct. What's the problem with it?
 
Upvote 0
if i insert msg.subject- backuped mail is with 0 KB . Any ideas?

Code:
Sub backup_selectioProject1()
Dim FNme As String
Dim dtDate As Date
Dim msg As Object
 
DirName = "Z:\Departments-WUIB\07 - Accounting Euroc\ACCOUNTING\Vilnius WUIB_WUBS\Emails back-ups\Project team\"
For Each msg In Application.ActiveExplorer.Selection
dtDate = msg.ReceivedTime
eSub = msg.Subject
     
     FNme = DirName & eSub & "_" & Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, _
vbUseSystem) & ".MSG"
    
    
     If TypeName(msg) = "MailItem" Then
       msg.SaveAs FNme, olMSG
       
       
    End If
     
    Next
End Sub
 
Upvote 0
Looking at that, I suspect the complete path is too long. Does it work if you save to say C:\Test instead of that long network path?
 
Upvote 0
What is the subject of the email?
 
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