choosing outlook folder

  • Thread starter Thread starter Southern at Heart
  • Start date Start date
S

Southern at Heart

I once saw some vba for a little process that opened a dialog box and allowed
the user to choose an outlook folder (I need it to choose which contact
folder to retrieve data from)
Anyone seen this or know how to do this?
thanks,
 
Southern at Heart said:
I once saw some vba for a little process that opened a dialog box and
allowed
the user to choose an outlook folder (I need it to choose which contact
folder to retrieve data from)
Anyone seen this or know how to do this?
thanks,

Paste the following code into a new standard module:

''' START CODE '''
Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
'
Private Declare Function SHGetPathFromIDListA Lib "shell32.dll" _
(ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolderA Lib "shell32.dll" _
(lpBrowseInfo As BROWSEINFO) As Long

Public Function SelectFolder(Optional hWnd As Long, _
Optional Prompt As String) As String
Dim bi As BROWSEINFO
Dim Buffer As String, itemID As Long
'
If hWnd = 0 Then hWnd = Application.hWndAccessApp
If Prompt = "" Then Prompt = "Please Select Folder"
With bi
.hOwner = hWnd
.ulFlags = 1
.lpszTitle = Prompt
End With
Buffer = Space$(512)
itemID = SHBrowseForFolderA(bi)
If SHGetPathFromIDListA(itemID, Buffer) Then
SelectFolder = Left(Buffer, InStr(Buffer, vbNullChar) - 1)
End If
End Function
''' END CODE '''

Example call from a form (form's PopUp property must be set to Yes/True for
this to work properly) :

Me.txtResult = SelectFolder(Me.hWnd, "Please select the folder you want:")

Example call from a module (ie no available hWnd) :

Me.txtResult = SelectFolder(, "Please select the folder you want:")
 
Back
Top