none
Outlook VBA move an email to a shared folder RRS feed

  • Question

  • hello gurus, is there a way that to create a macro and move the current selected email to a shared folder?

    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.

    Tuesday, March 4, 2014 10:01 AM

Answers

  • Hello,

    Yes, you can create a macro for moving the currently selected email to a shared folder. The Selection property of the Explorer class can be used for

     Dim myOlExp As Outlook.Explorer  
     Dim myOlSel As Outlook.Selection  
     Dim oMail As Outlook.MailItem 
    
     Set myOlExp = Application.ActiveExplorer  
     Set myOlSel = myOlExp.Selection  
     For x = 1 To myOlSel.Count  
     If myOlSel.Item(x).Class = OlObjectClass.olMail Then  
       ' For mail item, use the SenderName property.  
       Set oMail = myOlSel.Item(x) 
     End If 

    To get a shared folder you can use the GetSharedDefaultFolder method of the Namespace class.

     Set CalendarFolder = myNamespace.GetSharedDefaultFolder _  
     (myRecipient, olFolderCalendar) 

    Or use the OpenSharedFolder method:

    Set oNamespace = Application.GetNamespace("MAPI")  
     Set oFolder = oNamespace.OpenSharedFolder( _  
     "webcal://icalx.com/public/icalshare/US32Holidays.ics") 

    Finally, the Move method of the MailItem class should be used for moving a Microsoft Outlook item to a new folder.


    • Edited by Eugene Astafiev Tuesday, March 4, 2014 10:18 AM
    • Marked as answer by cguan Wednesday, March 5, 2014 2:27 PM
    Tuesday, March 4, 2014 10:17 AM

All replies

  • Hello,

    Yes, you can create a macro for moving the currently selected email to a shared folder. The Selection property of the Explorer class can be used for

     Dim myOlExp As Outlook.Explorer  
     Dim myOlSel As Outlook.Selection  
     Dim oMail As Outlook.MailItem 
    
     Set myOlExp = Application.ActiveExplorer  
     Set myOlSel = myOlExp.Selection  
     For x = 1 To myOlSel.Count  
     If myOlSel.Item(x).Class = OlObjectClass.olMail Then  
       ' For mail item, use the SenderName property.  
       Set oMail = myOlSel.Item(x) 
     End If 

    To get a shared folder you can use the GetSharedDefaultFolder method of the Namespace class.

     Set CalendarFolder = myNamespace.GetSharedDefaultFolder _  
     (myRecipient, olFolderCalendar) 

    Or use the OpenSharedFolder method:

    Set oNamespace = Application.GetNamespace("MAPI")  
     Set oFolder = oNamespace.OpenSharedFolder( _  
     "webcal://icalx.com/public/icalshare/US32Holidays.ics") 

    Finally, the Move method of the MailItem class should be used for moving a Microsoft Outlook item to a new folder.


    • Edited by Eugene Astafiev Tuesday, March 4, 2014 10:18 AM
    • Marked as answer by cguan Wednesday, March 5, 2014 2:27 PM
    Tuesday, March 4, 2014 10:17 AM
  • Thanks Eugene :)

    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.

    Wednesday, March 5, 2014 2:28 PM