locked
VBA to reference an EAS folder RRS feed

  • Question

  • I am trying to modify some vba so that I can archive some emails to my EAS folder in OUTLOOK 2010

    My code fails at this line

    Sub Archive()
    
        Dim objOutlook As Outlook.Application
        Dim objNamespace As Outlook.NameSpace
        Dim objSourceFolder As Outlook.MAPIFolder
        Dim objDestFolder As Outlook.MAPIFolder
        Dim objVariant As Variant
        Dim lngMovedItems As Long
        Dim intCount As Integer
        Dim intDateDiff As Integer
        Dim strDestFolder As String
    
        Set objOutlook = Application
        Set objNamespace = objOutlook.GetNamespace("MAPI")
        Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderInbox)
    
        ' use a subfolder under Inbox ***CODE FAILS HERE!!!***
        Set objDestFolder = objNamespace.Folders("MyEAS").Folders("Inbox")
    
        For intCount = objSourceFolder.Items.Count To 1 Step -1
            Set objVariant = objSourceFolder.Items.Item(intCount)
            DoEvents
            If objVariant.Class = olMail Then
    
                 intDateDiff = DateDiff("d", objVariant.SentOn, Now)
    
                ' I'm using 7 days, adjust as needed.
                If intDateDiff > 28 Then
    
                  objVariant.Move objDestFolder
    
                  'count the # of items moved
                   lngMovedItems = lngMovedItems + 1
    
                End If
            End If
        Next
    
        ' Display the number of items that were moved.
        MsgBox "Moved " & lngMovedItems & " messages(s)."
    Set objDestFolder = Nothing
    End Sub


    Tuesday, July 5, 2016 7:51 AM

Answers

  • >>>I am trying to modify some vba so that I can archive some emails to my EAS folder in OUTLOOK 2010

    According to your description, I have created Hotmail Exchange ActiveSync (EAS) folder like below:

    then use this created folder name, but I am not able to reproduce your issue,

    So I suggest that you could make sure this folder name is correct:

    For Each folder In objNamespace.Folders
           Debug.Print folder.Name
    Next folder

    For more information, click here to refer about Configure Outlook with an Outlook.com (Hotmail), Gmail, Office 365, Yahoo, AOL or iCloud account

    In addition you’re unable to move email message items from PST file into Exchange Active Sync data file.
    This is a limitation of Exchange Active Sync account configured in Outlook.

    For information on this, you may refer to the article given below:

    http://support2.microsoft.com/kb/2781261

    Disclaimer: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Wednesday, July 6, 2016 2:29 AM