Consulting

Results 1 to 5 of 5

Thread: VBA to move mail from Gmail 'Important' folder in Outlook to Inbox

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Aug 2009
    Posts
    24
    Location

    VBA to move mail from Gmail 'Important' folder in Outlook to Inbox

    I have set up Outlook to retrieve all of my gmail. Unfortunately however, most of the emails are going to the 'Important' folder, hidden in the [Gmail] folder.
    I'm trying to write a macro to automatically move all mail from Important to Inbox, and have this code, but am getting an error. My experience in writing code is extremely poor, so I tend to google and then try to modify - which works out badly!!

    My folder structure is (The folders inside the Gmail folder are the first 3)

    Inbox
    >[Gmail]
    Important
    Drafts
    Sent Mail
    ......
    Outbox
    Search Folders

    Can somebody indicate where I am going wrong? Thanks!!!


    Sub MoveItems()
      Dim myNameSpace As Outlook.NameSpace
      Dim myInbox As Outlook.Folder
      Dim myDestFolder As Outlook.Folder
      Dim myItems As Outlook.Items
      Dim myItem As Object
      Set myNameSpace = Application.GetNamespace("MAPI")
      Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
      Set myItems = myInbox.Items
      Set myDestFolder = myInbox.Folders("Important")
      Set myItems = myInbox.Folders("Inbox").Items
      'Debug.Print myItems.Count
      For i = myItems.Count To 1 Step -1 'Iterates from the end backwards
       myItems.Item(i).Move myDestFolder
      Next
    End Sub
    Last edited by Aussiebear; 03-11-2023 at 11:44 PM. Reason: Added code tags to supplied code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •