troubleshooting Question

Outlook Macro rules to move mails to folders. David's script. Need some addition.

Avatar of bsharath
bsharathFlag for India asked on
Outlook
10 Comments1 Solution1394 ViewsLast Modified:
Hi,

Outlook Macro rules to move mails to folders. David's script. Need some addition.

I have this script which works perfect. But i dont want it to run automatically. As i receive all mails into inbox. I just want to run the macro once a while to get all moved accordinglt. So what are the changes required.

Regards
Sharath
Sub FileMessages(Item As Outlook.MailItem)
    Dim strFoldername As String, _
        olkFolder As Outlook.Folder
    Select Case Item.SenderName
        'Add the following two lines for each sender you want to file messages for.
        Case "Sharath"
            strFoldername = "Latest Mails\Inbox\sharath"
           End Select
    If strFoldername <> "" Then
        Set olkFolder = OpenOutlookFolder(strFoldername)
        Item.Move olkFolder
    End If
    Set olkFolder = Nothing
End Sub
 
Function IsNothing(obj)
  If TypeName(obj) = "Nothing" Then
    IsNothing = True
  Else
    IsNothing = False
  End If
End Function
 
Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder
    Dim arrFolders As Variant, _
        varFolder As Variant, _
        olkFolder As Outlook.MAPIFolder
    On Error GoTo ehOpenOutlookFolder
    If strFolderPath = "" Then
        Set OpenOutlookFolder = Nothing
    Else
        If Left(strFolderPath, 1) = "\" Then
            strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
        End If
        arrFolders = Split(strFolderPath, "\")
        For Each varFolder In arrFolders
            If IsNothing(olkFolder) Then
                Set olkFolder = Session.Folders(varFolder)
            Else
                Set olkFolder = olkFolder.Folders(varFolder)
            End If
        Next
        Set OpenOutlookFolder = olkFolder
    End If
    On Error GoTo 0
    Exit Function
ehOpenOutlookFolder:
    Set OpenOutlookFolder = Nothing
    On Error GoTo 0
End Function
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros