User Tools

Site Tools


start:promomail

This is an old revision of the document!


Email Settings

GMail account

orders.picnicpromotions@gmail.com Credentials

Outlook VB Macro to copy mail to folder

'Outlook VB Macro to copy selected mail item(s) to a target folder
Sub CopyToGmail()
On Error Resume Next

Dim ns As Outlook.NameSpace
Dim CopyToFolder As Outlook.MAPIFolder
Dim objItem As Outlook.MailItem

Set ns = Application.GetNamespace("MAPI")

'Define path to the target folder
Set CopyToFolder = ns.Folders("testpicnictime@gmail.com").Folders("Inbox")

If Application.ActiveExplorer.Selection.Count = 0 Then
   MsgBox ("No item selected")
   Exit Sub
End If

If CopyToFolder Is Nothing Then
   MsgBox "Target folder not found!", vbOKOnly + vbExclamation, "Move Macro Error"
End If

For Each objItem In Application.ActiveExplorer.Selection
   If CopyToFolder.DefaultItemType = olMailItem Then
      If objItem.Class = olMail Then
         objItem.Copy CopyToFolder
         objItem.Move CopyToFolder
      End If
  End If
Next

Set objItem = Nothing
Set CopyToFolder = Nothing
Set ns = Nothing

End Sub
start/promomail.1489685671.txt.gz · Last modified: 2017/03/16 10:34 by andre