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: 541
  • outlook macro 3 - without sub folder.txt
    2.9 KB · Views: 482

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: 545

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: 554
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: 532

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
N Line to move origEmail to subfolder within a reply macro Outlook VBA and Custom Forms 0
T Macro to move reply and original message to folder Outlook VBA and Custom Forms 6
Witzker Macro to move @domain.xx of a Spammail to Blacklist in Outlook 2019 Outlook VBA and Custom Forms 7
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
J Outlook 365 Outlook Macro to Sort emails by column "Received" to view the latest email received Outlook VBA and Custom Forms 0
J Macro to send email as alias Outlook VBA and Custom Forms 0
M Outlook Macro to save as Email with a file name format : Date_Timestamp_Sender initial_Email subject Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro GoTo user defined search folder Outlook VBA and Custom Forms 7
D Outlook 2016 Creating an outlook Macro to select and approve Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro to send an Email Template from User Defined Contact Form Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro to check Cursor & Focus position Outlook VBA and Custom Forms 8
V Macro to mark email with a Category Outlook VBA and Custom Forms 4
M Outlook 2019 Macro not working Outlook VBA and Custom Forms 0
S Outlook 365 Help me create a Macro to make some received emails into tasks? Outlook VBA and Custom Forms 1
Geldner Send / Receive a particular group via macro or single keypress Using Outlook 1
D Auto Remove [EXTERNAL] from subject - Issue with Macro Using Outlook 21
V Macro to count flagged messages? Using Outlook 2
sophievldn Looking for a macro that moves completed items from subfolders to other subfolder Outlook VBA and Custom Forms 7
S Outlook Macro for [Date][Subject] Using Outlook 1
E Outlook - Macro - send list of Tasks which are not finished Outlook VBA and Custom Forms 3
E Macro to block senders domain Outlook VBA and Custom Forms 1
D VBA Macro to Print and Save email to network location Outlook VBA and Custom Forms 1
N VBA Macro To Save Emails Outlook VBA and Custom Forms 1
Witzker Outlook 2019 Macro to answer a mail with attachments Outlook VBA and Custom Forms 2
A Outlook 2016 Macro to Reply, ReplyAll, or Forward(but with composing new email) Outlook VBA and Custom Forms 0
J Macro to Insert a Calendar Outlook VBA and Custom Forms 8
W Macro to Filter Based on Latest Email Outlook VBA and Custom Forms 6
D Autosort macro for items in a view Outlook VBA and Custom Forms 2
S HTML to Plain Text Macro - Help Outlook VBA and Custom Forms 1
A Macro to file emails into subfolder based on subject line Outlook VBA and Custom Forms 1
N Help creating a VBA macro with conditional formatting to change the font color of all external emails to red Outlook VBA and Custom Forms 5
S Visual indicator of a certain property or to show a macro toggle Outlook VBA and Custom Forms 2
L Modifying VBA script to delay running macro Outlook VBA and Custom Forms 3
S Macro to extract and modify links from emails Outlook VBA and Custom Forms 3
M Replyall macro with template and auto insert receptens Outlook VBA and Custom Forms 1
L Macro to add Date & Time etc to "drag to save" e-mails Outlook VBA and Custom Forms 17
S Macro for Loop through outlook unread emails Outlook VBA and Custom Forms 2
Globalforester ItemAdd Macro - multiple emails Outlook VBA and Custom Forms 3

Similar threads

Top