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!!!
Code:
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