Solved

Outlook Set Mapifolder to a string?  How do I do that?

Posted on 2003-12-05
1
518 Views
Last Modified: 2010-05-01
I have some code that I want to cycle through a certain Inbox and save the Attachments.  This Inbox may change but I do know the path..

"\\Mailbox - 3114 Test\Inbox"  one time
"\\Mailbox - 3115 Test\Inbox" next ...
       
        Dim myOlapp As Outlook.Application
        Dim myoMsg As Outlook.MailItem
        Dim myOFolder As Outlook.MAPIFolder
     
        myOlapp = CreateObject("Outlook.Application")
        myoMsg = myOlapp.CreateItem(Outlook.OlItemType.olMailItem)
 --     myOFolder  = "\\Mailbox - 3114 Westin\Inbox" -----

Here is where I get an error?  How do I set the folder to this string?

Thanks,

Rog
0
Comment
Question by:Rog
1 Comment
 
LVL 44

Accepted Solution

by:
bruintje earned 125 total points
ID: 9884797
there is a good sample here

source : http://www.slipstick.com/dev/code/getfolder.htm

Public Function GetFolder(strFolderPath As String)As MAPIFolder

  ' folder path needs to be something like

  '   "Public Folders\All Public Folders\Company\Sales"

  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 = CreateObject("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

hope this helps a bit
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now