• Reading Outlook mail (97-SR2)

    Author
    Topic
    #360266

    I have written VBA to read email from my Outlook inbox, but need to read from the inbox for a “secondary” mail folder. I.e. I use “File | Open | Other User’s Folder..” to open the second folder which is used to receive email sent from a website -so it doesn’t fill my mailbox up!

    How do I tell Access to look in the other folder?

    Thanks!

    Larry

    Viewing 0 reply threads
    Author
    Replies
    • #542132

      Try something like:

      Public Sub ListMessageSubjects()

      Dim appOutlook As Outlook.Application
      Dim objNameSpace As Object
      Dim objFolder As MAPIFolder
      Dim objMailItem As Object

      Set appOutlook = CreateObject(“Outlook.Application”)
      Set objNameSpace = appOutlook.GetNamespace(“MAPI”)

      Set objFolder = objNameSpace.Folders(“Your Folder Name Here”)

      For Each objMailItem in objFolder.Items

      Debug.Print objMailItem.Subject

      Next objMailItem

      appOutlook.Quit

      End Sub

      If you want to “drill down” into nested folders, then append .Folders(“Next level down folder name”); e.g.:

      Set objFolder = objNameSpace.Folders(“Your Folder Name Here”).Folders(“Next level down folder name”)

      Add more to drill further.

      Hope this helps a little.

      Tom

      • #542247

        Tom,

        Thanks for the help – this lets me reads from folders within my personal mailbox, using the syntax:

        Set objFolder = objNameSpace.Folders(“Mailbox – My name”).Folders(“Next level down folder name”)

        I still can’t figure out the name of the “attached” folder. The folder says “Fire Drill – Inbox” , but I haven’t found the right combination of folders and subfolder names to get it open. I’ll check with our IT folks for suggestions. If you have any thoughts, I’d love to hear them.

        Thanks again

        Larry

        • #542340

          Larry,

          Rather than one-time opening the folder of interest (as you describe), add it “permanently” to your Outlook folder list. To do this (assuming you’re using Microsoft Exchange Server), first select Tools | Services. Then select “Microsoft Exchange Server” and click the Properties button. Then click the Advanced Tab, then the Add… button and type in the mailbox name (e.g., “John Doe”). Click OK a few times to get out of all this. Now, you should have this mailbox listed in your folder list, in addition to your own mailbox.

          Once this is done (it becomes part of your profile so you won’t have to do it again the next time you open Outlook), THEN you can use the VBA code I provided above (which, now that I better understand your problem, is probably similar to what you were already using to access your own mailbox):

          Set objFolder = objNameSpace.Folders(“Mailbox – John Doe”).Folders(“Inbox”)

          or something similar.

          Does this get you closer?

          Tom

    Viewing 0 reply threads
    Reply To: Reading Outlook mail (97-SR2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: