Results 1 to 8 of 8
  1. #1
    Star Lounger
    Join Date
    Mar 2008
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There are two things I need help figuring out. The first one is I'm trying to figure out how to retrieve emails from a group outlook mailbox inbox. I've put together the below code which works fine for retrieving emails from the default mailbox inbox, but I can't figure out how to tell it to look in another email box that I have access to. I'm currently using late binding coding and would prefer to keep it this way if possible. The second thing I need to figure out is how to move the email once it's been looked at to a specified folder such as a personal archive folder. Any help with this would be appreciated. Please see the below and let me know of any suggestions there may be. Thanks in advance.



    Sub GetFromInbox()

    Dim olApp As Object
    Dim olNs As Object
    Dim Fldr As Object
    Dim olMail As Object
    Dim olAtt As Object
    Dim TempFile As String

    Set olApp = GetObject(, "Outlook.Application")
    If olApp Is Nothing Then
    Set olApp = CreateObject("Outlook.Application")
    End If
    Set olNs = olApp.GetNamespace("MAPI")
    Set Fldr = olNs.GetDefaultFolder(6) ' Inbox

    '************************************************
    ' Need to figure out how to retreive emails from
    ' the inbox of a group email box. Group mailbox
    ' name is DMO reporting. Trying to accomplish this
    ' using late binding VBA coding.
    '************************************************

    TempFile = Environ$("temp") & "\" ' Set temp file location
    SubjName = InputBox("Enter the email subject line.", "Subject line required")
    If SubjName = "" Then
    MsgBox ("You did not specify a subject line to look for. Please" & vbNewLine & _
    "specify a subject line and try your request again."), _
    vbExclamation, "Subject line required"
    GoTo eHandler
    End If

    For Each olMail In Fldr.Items
    If olMail.Subject = SubjName Then
    For Each olAtt In olMail.Attachments
    AttName = olAtt.Filename
    olAtt.SaveAsFile TempFile & olAtt.Filename
    Next olAtt
    End If

    ' olMail.Move (Not sure how to specify a specific sub folder using late binding)

    '************************************************* ************************
    ' Need to figure out how to move the email from the inbox to a new folder.
    ' Specificlly looking to move the emails to a personal archive folder
    ' using late binding VBA coding.
    '************************************************* ************************

    Next olMail

    eHandler:
    ' Set object variables to nothing
    Set olAtt = Nothing
    Set olMail = Nothing
    Set Fldr = Nothing
    Set olNs = Nothing
    Set olApp = Nothing

    End Sub

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts
    You have posted this in the Excel Forum - are you running this code from Excel, and since it doesn't seem to use any Excel objects, would you be better off running it from Outlook?
    -John ... I float in liquid gardens
    UTC -7ąDS

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    I have moved this topic from the Excel forum to the Outlook forum since it's about Outlook VBA.

  4. #4
    Star Lounger
    Join Date
    Mar 2008
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='779128' date='10-Jun-2009 11:54']I have moved this topic from the Excel forum to the Outlook forum since it's about Outlook VBA.[/quote]


    This routine will run directly from Excel. None of it runs in outlook but it does create instances of outlook to retrieve emails from it.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    [quote name='b0bito' post='779130' date='10-Jun-2009 18:02']This routine will run directly from Excel. None of it runs in outlook but it does create instances of outlook to retrieve emails from it.[/quote]
    Yes, but your question has nothing to do with Excel VBA, only with Outlook VBA, even if you run it from Excel.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Instead of

    Set Fldr = olNs.GetDefaultFolder(6) ' Inbox

    you can use

    Set Fldr = olNs.Folders("DMO Reporting")

    or if you want to go a level deeper

    Set Fldr = olNs.Folders("DMO Reporting").Folders("Inbox")

    etc.

    To move an item:

    Dim olTarget As Object
    Set olTarget = olNs.Folders("Archive Folders")
    olMail.Move olTarget

    Of course, olTarget can also be a folder at a lower level:

    Set olTarget = olNs.Folders("Archive Folders").Folders("Special Archive").Folders("2009 Archive")

  7. #7
    Star Lounger
    Join Date
    Mar 2008
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the suggestions. I tried the folders option several times and couldn't get it to work so that's why I posted my question. I was able to find what I was doing wrong. Since the mailbox I'm trying to access is a shared mailbox and not my defauly mailbox. When specifying the folders option. I had to include "Mailbox - ". The below is what I had to do to get this to work correctly.

    Set Fldr = olNs.Folders("Mailbox - DMO Reporting")

    Thanks again for the help!

  8. #8
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts
    [quote name='b0bito' post='779153' date='10-Jun-2009 11:15']Set Fldr = olNs.Folders("Mailbox - DMO Reporting")[/quote]
    In the Outlook Immediates window,

    ?ActiveExplorer.CurrentFolder.FolderPath

    will get you the path up through to the parent folder, from there you get get the mailbox or PST name.
    -John ... I float in liquid gardens
    UTC -7ąDS

Posting Permissions

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