This is code from John Walkenbach's book "Excel 2000 Power Programming with VBA":
The Sub at the bottom is just a test for the call...which isn't workingVB Code:
Option Explicit '32-bit API declarations Declare Function SHGetPathFromIDList Lib "shell32.dll" _ Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal _ pszpath As String) As Long Declare Function SHBrowseForFolder Lib "shell32.dll" _ Alias "SHBrowseForFolderA" (lpBrowseInfo As BrowseInfo) _ As Long Public 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 Function GetDirectory(Optional msg) As String Dim bInfo As BrowseInfo Dim path As String Dim r As Long, x As Long, pos As Integer 'Root folder = Desktop bInfo.pIDLRoot = 0& 'Title in the dialog If IsMissing(msg) Then bInfo.lpszTitle = "Please select the folder where 'Old Bio-Analytical MS.xls' exists." Else bInfo.lpszTitle = msg End If 'Type of directory to return bInfo.ulFlags = &H1 'Display the dialog x = SHBrowseForFolder(bInfo) 'Parse the result path = Space$(512) r = SHGetPathFromIDList(ByVal x, ByVal path) If r Then pos = InStr(path, Chr$(10)) [COLOR=Red]GetDirectory = Left(path, pos - 1)[/COLOR] Else GetDirectory = "" End If End Function Sub GetAFolder() Dim msg As String msg = "Please select a location for the backup." MsgBox GetDirectory(msg) End Sub![]()
I get the error where the red text is. Apparently variable pos = 0![]()
Any ideas????






Reply With Quote