0

Does anyone have excel vba code to copy and paste to loop through gmail emails in a gmail inbox?

While there is a ton out there about:

1) sending gmail with excel vba;

2) looping through emails with excel vba in outlook; and

3) looping through gmail emails in a gmail inbox using other programming languages;

I couldn't find anything to loop through gmail emails in a gmail inbox.

I know I'm actually asking for quite the finished product. It's not that I'm hoping that anyone would be so kind as to write the code for me, but I am hoping that someone might have it already.

After all my attempts to tweak the code I was able to find relative to 1), 2) and 3) above, it became clear to me that I just need to go ahead and post this question. (Who knows, it may help a ton of other folks too.)

h10b
  • 9
  • 3
  • This question may be better suited for [SuperUser.com](http://superuser.com/) than SO. As you stated, you're asking for some code someone has. You also have three questions - 1 is possible, [Google](https://www.google.com/search?q=VBA+gmail&oq=VBA+gmail) has plenty results for that 2 is probably possible, just use VBA in Outlook (why go through Excel?), 3 is probably quite tricky since the gmail inbox is web-based. Also, what code did you try? Please post what you've done, as SO is not a "code for me" or "give me the code" type site. See [how to ask](http://stackoverflow.com/help/how-to-ask). – BruceWayne May 04 '16 at 14:35

1 Answers1

0

You just need to use the names of the folder, check the following

Sub SetFlagIcon()
    Dim mpfInbox As Outlook.Folder
    Dim obj As Outlook.MailItem
    Dim i As Integer
    Set mpfInbox = Application.GetNamespace("MAPI").Folders("john.smith@gmail.com").Folders("[Gmail]").Folders("Sent Mail")
    ' Loop all items in the Inbox\Test Folder
    For i = 1 To mpfInbox.Items.Count
        If mpfInbox.Items(i).Class = olMail Then
            Set obj = mpfInbox.Items.Item(i)
            For Each Recipient In obj.Recipients
                If Recipient.Address = "myfriend@hotmail.com" Then
                    'Set the yellow flag icon
                    obj.FlagIcon = olYellowFlagIcon
                    obj.Save
                End If
            Next Recipient
        End If
    Next
End Sub
Jeanno
  • 2,769
  • 4
  • 23
  • 31