Macro to move E-mail

Status
Not open for further replies.
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
I have a macro that works great in office 2010, however we recently upgraded our computers and now have office 2013. The macro still works but it can take up 4 or 5 mins to finish the macro where before it happened in about 5-10 seconds.

Details:
Before Office 2010
Current Office 2013

Load Time Before: 5-10 seconds
Load Time 2013: 4-5 mins

Using Outlook with an exchange server and retention folders

I have attached the macro I'm using along with a screen shot of what my outlook folder looks like.

What I'm trying to simply accomplish is to move ALL e-mail that is in my inbox & sent mail folder to my 7 year retention folder if it is older than 60 days.

This also loads at start up of outlook 2013

-----
Is there a way to speed this back up?
 

Attachments

  • Capture.PNG
    Capture.PNG
    6.1 KB · Views: 389
  • outlook macro 3 - without sub folder.txt
    2.9 KB · Views: 318

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
i thought maybe it was slow as an autostart. i use a similar macro in 2013 and its speed is acceptable, but when i run it, i'm moving half the messages in the folder (around 2000 get moved). If you run it on start, there shouldn't be a lot of messages to move every day. How is the speed if you do each folder individually?
 
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
I have tried only doing one folder (inbox) and its the same. It typically only moves 1-3 messages out of each folder when it does run. It would be no issue if it ran slowly and still allowed outlook to function but it will not receive any e-mail until it has completed.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
The first time, with the first message box and moving 30 and almost 2000 messages, it took 4 minutes start to finish. (I had 3000 and 5000 messages in each folder).

If I remove the first msgbox, i can move between 50 and 100 total in under 17 seconds (Now around 3000 in each folder. )

if you want the count, do something like this for the inbox instead of the msgbox then add strInboxCount to the sent folder's msgbox - that saves me 5 seconds (yes, I'm slow!)
strInboxCount = "Moved " & lngMovedItems & " messages(s) From your Inbox."
[DOUBLEPOST=1418926256][/DOUBLEPOST]BTW, are you using cached or online mode? I'm testing with cached.
 
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
Cached mode, and i don't understand what is going on now, when i try to run the script (that worked previously) im getting an error

Any thoughts?
 

Attachments

  • Capture.PNG
    Capture.PNG
    25.5 KB · Views: 374

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
That is an odd error - it looks like its saying the macro is in a class module. It should be in ThisOutlookSession.
Did you change any references in Tools, references?
We know the code is fine, it works here.
 
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
I have changed nothing... About 2 weeks ago i upgraded to office 2013, it was so slow that i deleted it, i re pasted it back in to try the suggestion you gave but even with the old code im getting the error. I try the same thing on another computer and it works fine... i will try and repair office to see if that resolves the issue
 

Attachments

  • Capture.PNG
    Capture.PNG
    130.4 KB · Views: 378
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
so i have no idea why it works now and didnt 2 mins ago but anyways...

I tried to enter the new code you gave me, but it does not display any message once complete...

did i enter it wrong?

Code:
Private Sub Application_Startup()
Dim objOutlook As Outlook.Application
    Dim objNamespace As Outlook.NameSpace
    Dim objSourceFolder As Outlook.MAPIFolder
    Dim objDestFolder As Outlook.MAPIFolder
    Dim objVariant As Variant
    Dim lngMovedItems As Long
    Dim intCount As Integer
    Dim intDateDiff As Integer
    Dim strDestFolder As String
    
'''''''''' '''''''''' '''''''''' ''''''''''
'''''''''' Inbox Folder  ''''''''''
'''''''''' '''''''''' '''''''''' ''''''''''

    Set objOutlook = Application
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderInbox)
    
    ' use a subfolder under Inbox
    Set objParent = Session.GetDefaultFolder(olFolderInbox)
    Set objManaged = objParent.Parent.Folders("Managed Folders")
    Set objDestFolder = objManaged.Folders("7 Year Retention")

    For intCount = objSourceFolder.Items.Count To 1 Step -1
        Set objVariant = objSourceFolder.Items.Item(intCount)
        DoEvents
        If objVariant.Class = olMail Then
            
             intDateDiff = DateDiff("d", objVariant.SentOn, Now)
             
            ' I'm using 60 days, adjust as needed.
            If intDateDiff > 60 Then
              objVariant.Move objDestFolder
              
              'count the # of items moved
               lngMovedItems = lngMovedItems + 1
            End If
        End If
    Next
    
    ' Display the number of items that were moved.
strInboxCount = "Moved " & lngMovedItems & " messages(s) From your Inbox."
Set objDestFolder = Nothing

'''''''''' '''''''''' '''''''''' ''''''''''
'''''''''' Sent Mail Folder  ''''''''''
'''''''''' '''''''''' '''''''''' ''''''''''

      Set objOutlook = Application
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderSentMail)
    
    ' use a subfolder under Inbox
Set objParent = Session.GetDefaultFolder(olFolderInbox)
Set objManaged = objParent.Parent.Folders("Managed Folders")
Set objDestFolder = objManaged.Folders("7 Year Retention")

    For intCount = objSourceFolder.Items.Count To 1 Step -1
        Set objVariant = objSourceFolder.Items.Item(intCount)
        DoEvents
        If objVariant.Class = olMail Then
            
             intDateDiff = DateDiff("d", objVariant.SentOn, Now)
             
            ' I'm using 7 days, adjust as needed.
            If intDateDiff > 10 Then
              objVariant.Move objDestFolder
              
              'count the # of items moved
               lngMovedItems = lngMovedItems + 1
            End If
        End If
    Next
    
    ' Display the number of items that were moved.
   strInboxCount = "Moved " & lngMovedItems & " messages(s) From your Inbox."
Set objDestFolder = Nothing

End Sub
 

Attachments

  • Capture.PNG
    Capture.PNG
    4.7 KB · Views: 379

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
I wouldn't run this code in Application_Startup, but start a timer to run it after Outlook has completely startet up. See this sample for how to start the timer from the Application_Startup event. Add DisableTimer to the Timer procedure at the top so you'd get only one signal and then stop the timer. And move all your other code from Application_Startup to the Timer procedure.

Play with the timer interval if one minute is too short in your case.

Calling DoEvents is slowing it down. It allows Outlook to do other stuff and halt the execution of your code. I guess OL 2013 is doing more work than OL 2010 when startin up.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
Douglas Littlefield Macro to move mail from inbox to Managed Folder Exchange Server Administration 1
L Macro Move E-mail attachments to a PC Folder Using Outlook 16
J Macro to move mail from Inbox if older than 4 days Using Outlook 4
witzker Macro to move @domain.xx of a Spammail to Blacklist in Outlook 2019 Outlook VBA and Custom Forms 4
S Macro to move “Re:” & “FWD:” email recieved the shared inbox to a subfolder in outlook Outlook VBA and Custom Forms 0
Eike Move mails via macro triggered by the click of a button? Outlook VBA and Custom Forms 0
N Macro to move all recipients to CC while replying Outlook VBA and Custom Forms 0
B Macro to manually move selected emails to network folder Outlook VBA and Custom Forms 1
G email returns after running macro to move emails Outlook VBA and Custom Forms 1
S Macro to print & move selected emails? Using Outlook 3
G Macro to move sent items from local folder to IMAP folder Using Outlook 4
S Outlook macro to move replied / forwarded emails to a seperate folder Using Outlook 1
C Help with a Macro to move emails to a different PST data file Using Outlook 4
C Outlook VBA - Create Macro Move Contact field Item to Another Using Outlook 1
S Macro for other actions - Outlook 2007 Outlook VBA and Custom Forms 18
C Macro to extract sender name & subject line of incoming emails to single txt file Outlook VBA and Custom Forms 3
L Macro/VBA to Reply All, with the original attachments Outlook VBA and Custom Forms 2
S Outlook Macro to send auto acknowledge mail only to new mails received to a specific shared inbox Outlook VBA and Custom Forms 0
S Macro or plug-in to see if specific person was included in this email Outlook VBA and Custom Forms 3
U Macro for reminders,tasks,calendar Outlook VBA and Custom Forms 4
V macro runs slower on startup than after Outlook VBA and Custom Forms 3
A VBA macro for 15 second loop in send and received just for 1 specific mailbox Outlook VBA and Custom Forms 1
G VBA Macro Calendar Printing Assistant 4
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
M Outlook macro to automate search and forward process Outlook VBA and Custom Forms 6
R Macro Schedule every day in Outlook Using Outlook 0
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
Healy Consultants Macro to remove inside organization distribution list email address when reply to all recepients Outlook VBA and Custom Forms 0
geofferyh Cannot get Macro to SAVE more than one message attachment??? Outlook VBA and Custom Forms 5
N How can I increase/faster outlook VBA Macro Speed ? Using Outlook 2
4 Macro to set the category of Deleted Item? Outlook VBA and Custom Forms 2
D.Moore Folder view settings by VBA macro Outlook VBA and Custom Forms 57
A Outlook macro to create search folder with mail categories as criteria Outlook VBA and Custom Forms 3
Dave A Run macro on existing appointment when it changes Outlook VBA and Custom Forms 1
V Outlook Macro to show Flagged messages Outlook VBA and Custom Forms 2
O Run macro automatically at sending an email Using Outlook 11
R Retain Original Message When Forwarding With Macro Outlook VBA and Custom Forms 3
C Macro to add multiple recipients to message Outlook VBA and Custom Forms 3
B Reply and replyall macro is not working Outlook VBA and Custom Forms 1
O Macro - paste as plain text Outlook VBA and Custom Forms 2
J Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite Outlook VBA and Custom Forms 9
witzker Macro to set contact reminder to next day 9:00 Outlook VBA and Custom Forms 45
M Adding Macro to populate "to" "subject" "body" not deleting email string below. Outlook VBA and Custom Forms 5
E Copying data from e-mail attachement to EXCEL file via macro Outlook VBA and Custom Forms 38
M Macro to add date/time stamp to subject Outlook VBA and Custom Forms 4
R VBA macro - new message Outlook VBA and Custom Forms 3
S Example VBA Macro - To Conditionally Change the From Account and Add a BCC Address on Emails Outlook VBA and Custom Forms 11
S Macro using .SendUsingAccount only works the first time, after starting Outlook Outlook VBA and Custom Forms 4
S VBA Macro - Run-time error '424': object required - Help Please Outlook VBA and Custom Forms 3

Similar threads

Top