• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1505
  • Last Modified:

MS Outlook 2010 and Lync

I have MS Outlook 2010 and Lync which adds the folder “Conversation History”.  I have some vba that moves my deleted folder items to an external pst file each time I shut down Outlook.  I want to do the same thing for the Conversation History file but I cannot figure out what to use in the ‘GetDefaultFolder’ command.  Here is what I have tried for code and it fails to compile with “variable not defined” on the line “Set objTrash = Outlook.Application.Session.GetDefaultFolder(olFolderConversationHistory).Items”

Sub MoveConversationHistory()
     'Move messages from Exchange mailbox folder "Conversation History" to pst
     'Dim and Set
    Dim objFolder As Outlook.MAPIFolder
    Set objFolder = Outlook.Application.GetNamespace("MAPI").Folders("2013_ConversationHistory_Folder")
    Dim objTrash As Outlook.Items
    Set objTrash = Outlook.Application.Session.GetDefaultFolder(olFolderConversationHistory).Items
    Dim objDrafts As Outlook.Items

    Dim objItem As Object
    Dim objDraftItem As Object
    Dim varMsgID As String
   
    Dim varLoopCounter, x As Integer
   
    varLoopCounter = objTrash.Count
   
    For x = 1 To varLoopCounter
   
      Set objTrash = Outlook.Application.Session.GetDefaultFolder(olFolderConversationHistory).Items
   
      For Each objItem In objTrash

      '  Debug.Print "Moving Item: " & objItem.Subject & " - " & objItem.Class

        objItem.Move objFolder

        Exit For
      Next
   
    Next x
   
    Set objItem = Nothing
    Set objDraftItem = Nothing
    Set objFolder = Nothing
    Set objDrafts = Nothing
    Set objTrash = Nothing
   
End Sub

Thanks in advance,

Jim
0
phonepagerfax
Asked:
phonepagerfax
  • 2
  • 2
1 Solution
 
jrlingamCommented:
Hi

Its been so long since I wrote macros. I have just tried to get to the parent folder of Inbox which is the mailbox itself and then retrieve all the subfolders by their name.

Dim objNS As Outlook.Namespace
Dim objFolder As Outlook.MAPIFolder

Set objNS = Outlook.Application.GetNamespace("MAPI")

Dim varStr As String

Set objFolder = objNS.GetDefaultFolder(olFolderInbox)

varStr = objFolder.Parent

Set objMbx = objNS.Folders(varStr)

Set objFolder = objMbx.Folders("Conversations History")

Hope this helps.

Thanks
jrlingam.
0
 
phonepagerfaxAuthor Commented:
jrlingam,

I'm hopeful this will work.  When I compile the code I get objMbx variable not defined.  What should I dim it as?  I tried Outlook.Items but then I got objNs.Folders(varStr) type mismatch when I ran the code.  varStr did equal "myemail@mycompany.com".

Thanks for the help,

Jim
0
 
phonepagerfaxAuthor Commented:
jrlingam,

Thanks for the help, your comments got me thinking and I was able to get it to work.  Here is the code.  I hard coded the parent stuff but using your code I could make it dynamic but, in the end I don't care about this (yet) because I'm the only one using it.

Sub MoveConversationHistory()
'This moves all items from the Conversation History folder into the specific archive file

    'Move messages from Exchange mailbox folder "Conversation History" to pst
   
    Dim objDestinationFolder As Outlook.MAPIFolder
    Dim objSourceFolder As Outlook.MAPIFolder
    Dim objSourceFolderItems As Outlook.Items
    Dim objItem As Object
    Dim varMsgID As String
    Dim x As Integer
   
    'select the existing pst file
    Set objDestinationFolder = Outlook.Application.GetNamespace("MAPI").Folders("2013_ConversationHistory_Folder")
   
    'i think this gets all of the folders for the email address'
    Set objSourceFolder = Outlook.Application.GetNamespace("MAPI").Folders("me@mycompany.com")
   
    'this selects just the conversation history folder
    Set objSourceFolder = objSourceFolder.Folders("Conversation History")
   
    'this select all of the items in the folder
    Set objSourceFolderItems = objSourceFolder.Items
   
    'set the loop counter to the number of items in the folder
'    varLoopCounter = objSourceFolderItems.Count

      For Each objItem In objSourceFolderItems

        'Debug.Print "Moving Item: " & objItem.Subject & " - " & objItem.Class

        objItem.Move objDestinationFolder

      Next

    Set objItem = Nothing
    Set objDestinationFolder = Nothing
    Set objSourceFolder = Nothing
    Set objSourceFolderItems = Nothing

End Sub
0
 
jrlingamCommented:
Thanks for the update. Glad that I was able to assist you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now