Solved

MS Outlook 2010 and Lync

Posted on 2013-01-25
4
1,370 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Get an idea of what you should include in an email disclaimer with these Top 5 email disclaimer tips.
Set OWA language and time zone in Exchange for individuals, all users or per database.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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 …

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now