Solved

MS Outlook 2010 and Lync

Posted on 2013-01-25
4
1,392 Views
Last Modified: 2013-01-30
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
Comment
Question by:phonepagerfax
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
jrlingam earned 500 total points
ID: 38822575
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
 

Author Comment

by:phonepagerfax
ID: 38830934
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
 

Author Comment

by:phonepagerfax
ID: 38831243
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
 
LVL 3

Expert Comment

by:jrlingam
ID: 38838011
Thanks for the update. Glad that I was able to assist you.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Outlook Free & Paid Tools
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question