PDA

View Full Version : VB to access public folder from exchange server



pitspawn8
04-03-2009, 06:17 AM
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.

'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

Demosthine
04-09-2009, 09:36 AM
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.


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


Hope this helps.
Scott