Consulting

Results 1 to 5 of 5

Thread: Help accessing two diff outlook folders in VBA

  1. #1

    Help accessing two diff outlook folders in VBA

    Hello group - I've gotten stuck on an issue and I'm reaching out for help -

    I have a main inbox (a) that has it's own pst file.
    I have a 2nd mail file where I store archives (b), in a diff pst file.

    I'm trying to write a vba macro that will read messages from A do some processing and them move them to B if they meet certain criteria.

    I can do the first part and I know how to move messages within a particular file but when I try to reference a folder in B, I get a message telling me that outlook cannot find it.

    I'm quite sure that there is a way to do this - and I'm probably just not declaring things correctly - does anyone have any examples that I could review where two different Outlook folders are referenced and controlled using vba?
    Last edited by swisscheez; 01-15-2008 at 03:12 PM. Reason: accidentally posted twice

  2. #2
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    I am having exact same issue with tasks folder did yiu figure it out ???

    It is really frustrating (

  3. #3
    No I never found an answer - the issue is coming up again too. Did you find anything?

  4. #4
    VBAX Tutor Mavyak's Avatar
    Joined
    Jul 2008
    Posts
    204
    Location
    I created a new pst file and captioned the main folder "Secondary Folder". I then created a folder in that folder called "Folder In Secondary Folder pst". I then wrote the code below and it moved a message from the inbox of one pst file to a folder in another pst file.

    [vba]Sub TransferMessageBetweenPSTFiles()
    Dim M As MailItem
    Dim P As MAPIFolder
    Dim S As MAPIFolder
    Dim N As NameSpace
    Dim obj As Object

    Set N = Application.GetNamespace("MAPI")

    Set P = N.GetDefaultFolder(olFolderInbox)

    For Each obj In P.Items
    If obj.Class = olMail Then
    Set M = obj
    Exit For
    End If
    Next obj
    If M Is Nothing Then
    MsgBox "You don't have any mail!"
    GoTo ExitSub
    End If
    Set S = N.Folders("Secondary Folder").Folders("Folder In Secondary Folder pst")

    M.Move S

    ExitSub:
    If Not obj Is Nothing Then
    Set obj = Nothing
    End If
    If Not M Is Nothing Then
    Set M = Nothing
    End If
    Set P = Nothing
    Set S = Nothing
    Set N = Nothing
    End Sub[/vba]

  5. #5
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    mistake sorry

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •