-1

I am trying to create an Outlook Macro that will analyze the subject of an Inbox folder and decide where to move them to a subfolder or delete them based on a list of keywords for four different categories.

The problem is that the Inbox I am using is not the regular Inbox (I have two different Inbox folders, and this one is not the default one). So I need to target it in a way similar to writing the full path (Example: "\\xxx@xxx.net\Inbox\"). I tried to find an answer to it but all the info I found here relates to the assumption that we are working from the default Inbox.

Sub CountAttachmentsMulti2()
Dim oItem As Object
Dim iAttachments As Integer

For Each oItem In ActiveExplorer.Selection
    iAttachments = oItem.Attachments.Count + iAttachments

    If oItem.Attachments.Count <> 0 Then 'Si el mensaje contiene adjuntos
        NumofItems = oItem.Attachments.Count + NumofItems
        For j = 1 To oItem.Attachments.Count
            MsgBox oItem.Attachments.Item(j).DisplayName
            Value = oItem.Attachments.Item(j).DisplayName

            If InStr(LCase(Value), "su") > 0 Then
                MsgBox "Clap"
            End If

        Next j
    Else

        MsgBox oItem.Subject 'Get Subject Title
        NumofItems = NumofItems + 1
    End If

Next

MsgBox "Selected " & ActiveExplorer.Selection.Count & " messages with " & iAttachments & " attachements"

MsgBox "# of items = " & NumofItems
End Sub

This is the code I have tried initially, because before they have already separated by categories. So all that required is to count the total e-mails either by subject or number of attachments.

My issue right now is that I do not know how to target this e-mail account by using a full path.

If I know how to target that folder I think I can solve the rest of the problem myself.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Nwish1986
  • 35
  • 5

1 Answers1

0

After following the "possible-duplicate" link I was able to complete my code. I apologize because I did not know it was called a reference. Here is my complete solution to the issue:

Sub Test()

    Dim objNS As Outlook.NameSpace
    Dim objFolder As Outlook.MAPIFolder
    Dim Target_Folder As Outlook.MAPIFolder
    Dim oItem As Object
    Dim iAttachments As Integer

    Set objNS = GetNamespace("MAPI")
    Set objFolder_root = objNS.Folders("Testing") 'Getting Outlook Container
    Set objFolder = objFolder_root.Folders("Inbox") 'Target Inbox of the other container


    For Loops = objFolder.Items.Count To 1 Step -1
        Set oItem = objFolder.Items(Loops)
        If Category1(oItem.Subject) Then
            'MsgBox "Clap1"
            Set Target_Folder = objFolder_root.Folders("Category 1")
            oItem.Move Target_Folder
        ElseIf Category2(oItem.Subject) Then
            'MsgBox "Clap2"
            Set Target_Folder = objFolder_root.Folders("Category 2")
            oItem.Move Target_Folder
        ElseIf Category3(oItem.Subject) Then
            'MsgBox "Clap3"
            Set Target_Folder = objFolder_root.Folders("Category 3")
            oItem.Move Target_Folder
        ElseIf Category4(oItem.Subject) Then
            'MsgBox "Clap4"
            Set Target_Folder = objFolder_root.Folders("Category 4")
            oItem.Move Target_Folder
        Else
            MsgBox oItem.Subject & " does not belong to any of the 4 categories"
        End If

    Next

End Sub

Function Category1(value)
    Category_1_Keywords = Array("a")

    For i = 0 To UBound(Category_1_Keywords)
        If InStr(LCase(value), Category_1_Keywords(i)) > 0 Then
            Category1 = True
            Exit Function
        Else
            Category1 = False
        End If
    Next

End Function

There are, of course, more functions, I just posted the Category1 as a reference

0m3r
  • 12,286
  • 15
  • 35
  • 71
Nwish1986
  • 35
  • 5