none
CHALANGE! My code copies message form one to another folder in plain text... I need it to do it between accounts in one profile RRS feed

  • Question


  • I have this code that copies items from one folder to another and converts them to plain text.

    How do I modify code so that it moves items from profiles one account to profiles other account?


    Sub CopyPlainTextMSG()

    On Error Resume Next

       Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder
       Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem
       Set objNS = Application.GetNamespace("MAPI")
       Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
       Set objFolder = objInbox.Folders.Item("Dest_Folder")
       Set objItem = GetCurrentItem()

       objItem.Copy

       If objFolder Is Nothing Then
       End If

       If Application.ActiveExplorer.Selection.Count = 0 Then
           Exit Sub
       End If


       For Each objItem In Application.ActiveExplorer.Selection
           If objFolder.DefaultItemType = olMailItem Then
               If objItem.Class = olMail Then
               
                  objItem.Display
                  objItem.BodyFormat = olFormatPlain
                  objItem.Save
                  objItem.Close 1
                  objItem.Move objFolder
                   
               End If
           End If
       Next
                  

       Set objItem = Nothing
       Set objFolder = Nothing
       Set objInbox = Nothing
       Set objNS = Nothing

    End Sub
    ____________________________________________________________________
    Function GetCurrentItem() As Object

    Dim objApp As Outlook.Application
    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
    Case "Explorer"
    Set GetCurrentItem = _
    objApp.ActiveExplorer.Selection.Item(1)
    Case "Inspector"
    Set GetCurrentItem = _
    objApp.ActiveInspector.CurrentItem
    Case Else

    End Select
    End Function
     
    • Moved by Max Meng Thursday, January 24, 2013 2:12 AM
    Wednesday, January 23, 2013 12:42 PM

Answers

  • Hi Madars,

    Thank you for posting in the MSDN Forum.

    You can get all the accounts by using objNS.Accounts, you can get the specific accounts by using objNS.Accounts.Item() method.

    After you get a specific account, let name it as myAccount, you can then get the Inbox of it by using

    Set objInbox = myAccount.DeliveryStore.GetDefaultFolder(olFolderInbox)
    'Then you can get a specific folder
    Set objFolder = objInbox.Folders.Item() 
    'Don't forget pass the Index as parameter

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, January 24, 2013 12:48 PM
    Moderator

All replies


  • I have this code that copies items from one folder to another and converts them to plain text.

    How do I modify code so that it moves items from profiles one account (mailbox) to profiles other account (mailbox)?


    Sub CopyPlainTextMSG()

    On Error Resume Next

       Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder
       Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem
       Set objNS = Application.GetNamespace("MAPI")
       Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
       Set objFolder = objInbox.Folders.Item("Dest_Folder")
       Set objItem = GetCurrentItem()

       objItem.Copy

       If objFolder Is Nothing Then
       End If

       If Application.ActiveExplorer.Selection.Count = 0 Then
           Exit Sub
       End If


       For Each objItem In Application.ActiveExplorer.Selection
           If objFolder.DefaultItemType = olMailItem Then
               If objItem.Class = olMail Then
               
                  objItem.Display
                  objItem.BodyFormat = olFormatPlain
                  objItem.Save
                  objItem.Close 1
                  objItem.Move objFolder
                   
               End If
           End If
       Next
                  

       Set objItem = Nothing
       Set objFolder = Nothing
       Set objInbox = Nothing
       Set objNS = Nothing

    End Sub
    ____________________________________________________________________
    Function GetCurrentItem() As Object

    Dim objApp As Outlook.Application
    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
    Case "Explorer"
    Set GetCurrentItem = _
    objApp.ActiveExplorer.Selection.Item(1)
    Case "Inspector"
    Set GetCurrentItem = _
    objApp.ActiveInspector.CurrentItem
    Case Else

    End Select
    End Function
     

    Wednesday, January 23, 2013 1:55 PM
  • Hi Madars,

    Thank you for posting in the MSDN Forum.

    You can get all the accounts by using objNS.Accounts, you can get the specific accounts by using objNS.Accounts.Item() method.

    After you get a specific account, let name it as myAccount, you can then get the Inbox of it by using

    Set objInbox = myAccount.DeliveryStore.GetDefaultFolder(olFolderInbox)
    'Then you can get a specific folder
    Set objFolder = objInbox.Folders.Item() 
    'Don't forget pass the Index as parameter

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, January 24, 2013 12:48 PM
    Moderator