Consulting

Results 1 to 2 of 2

Thread: VB to access public folder from exchange server

  1. #1

    VB to access public folder from exchange server

    I have a code that prints .pdf attachments from a folder I select. I need the code to automatically chose a public folder from an exchange server.

    [VBA] 'The next four variable declarations are specific to Microsoft Outlook.
    Dim ns As NameSpace
    Dim smbbox As MAPIFolder
    Dim item As Object
    Dim atmt As Attachment

    'These are standard counters and variables.
    Dim filename, thedate As String
    Dim i As Integer

    'These lines are responsible for the folder that the e-mails will be pulled from.
    Set ns = GetNamespace("MAPI")
    Set smbbox = Application.GetNamespace("MAPI").PickFolder[/VBA]

  2. #2
    Good morning.

    I found an excellent example of this awhile back at http://www.outlookcode.com/d/code/getfolder.htm. It provides an excellent example with some explanations. The example code is shown below.

    [VBA]
    Public Function GetFolder2(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 = 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
    [/VBA]

    Hope this helps.
    Scott
    You don't understand anything until you learn it more than one way. ~Marvin Minsky

    I never teach my pupils; I only attempt to provide the conditions in which they can learn. - Albert Einstein

Posting Permissions

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