Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you access a different mailbox (not my inbox)

Status
Not open for further replies.

ToyFox

Programmer
Jan 24, 2009
161
0
0
US
I am building a routine to deal with attachments in a particular group mailbox. It works except its working in my inbox not the particular group mailbox...
How would I code for the group mailbox.


Set oOutlook = New Outlook.application
Set oNs = oOutlook.GetNamespace("MAPI")
Set oFldr = oNs.GetDefaultFolder(olFolderInbox)
 
If the group mailbox is setup to open as an additional mailbox in there default mailbox you should be able to use something like this:
Code:
Set oFldr = oOutlook.Session.Folders.Item("Mailbox - [i]Group Mailbox Name[/i]").Folders("Inbox")

If the group mailbox does not open with the default mail profile then I have no idea.

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
I use these two functions
Code:
Public Function getOutlookFolderPath() As String
   Dim olApp As Outlook.Application
   Dim olSession As Outlook.NameSpace
   Dim olStartFolder As Outlook.MAPIFolder
   Set olApp = New Outlook.Application
   Set olSession = olApp.GetNamespace("MAPI")
   Set olStartFolder = olSession.PickFolder
   If olStartFolder.DefaultItemType = 1 Then
     getOutlookFolderPath = olStartFolder.FolderPath
     getOutlookFolderPath = Mid(getOutlookFolderPath, 3)
   Else
     MsgBox "Can only import from a Calendar folder", vbInformation, "Pick a Calendar"
   End If
   
End Function
Public Function GetFolder(strFolderPath As String) As MAPIFolder
  ' strFolderPath needs to be something like
  '   "Public Folders\All Public Folders\Company\Sales" or
  '   "Personal Folders\Inbox\My Folder"

  Dim objApp As Outlook.Application
  Dim objNS As Outlook.NameSpace
  Dim colFolders As Outlook.Folders
  Dim objFolder As Outlook.MAPIFolder
  Dim arrFolders() As String
  Dim I As Long
'  On Error Resume Next

  strFolderPath = Replace(strFolderPath, "/", "\")
  arrFolders() = Split(strFolderPath, "\")
  Set objApp = Outlook.Application
  Set objNS = objApp.GetNamespace("MAPI")
  Set objFolder = objNS.Folders.Item(arrFolders(0))
  If Not objFolder Is Nothing Then
    For I = 1 To UBound(arrFolders)
      Set colFolders = objFolder.Folders
      Set objFolder = Nothing
      Set objFolder = colFolders.Item(arrFolders(I))
      If objFolder Is Nothing Then
        Exit For
      End If
    Next
  End If

  Set GetFolder = objFolder
  Set colFolders = Nothing
  Set objNS = Nothing
  Set objApp = Nothing
End Function

You need to get the string path to the folder and pass to second function. I use the first function to allow the user to click on a folder. This example was set for a calendar folder.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top