Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MS Outlook 2010 and Lync

Posted on 2013-01-25
4
Medium Priority
?
1,455 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
jrlingam earned 1500 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

Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

Question has a verified solution.

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

Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

688 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