Hallo,
ich habe seit VBA 7.1 ein Problem mit dem folgenden Code Teil.
In VBA 6.x ist es ohne Probleme gelaufen. Jetzt kommt die aussagekräftigste Fehlermeldung "Click OK to terminate" an der Stelle
"lpIDList = SHBrowseForFolder(udtBI)"
Kann mir jemand weiter helfen?
...
'VBA7
Private Declare PtrSafe Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare PtrSafe Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare PtrSafe Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Private Declare PtrSafe Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Private Sub CommandButton2_Click()
Dim iNull As Integer, lpIDList As Long, lResult As Long
Dim sPath As String, udtBI As BrowseInfo
With udtBI
'Set the owner window
'.hWndOwner = Me.hWnd
'lstrcat appends the two strings and returns the memory address
.lpszTitle = lstrcat("Please choose a directory!", "")
.pszDisplayName = lstrcat("Please choose a directory!", "")
'Return only if the user selected a directory
.ulFlags = 2 ^ 1 Or BIF_NEWFOLDERBUTTON
End With
'Show the 'Browse for folder' dialog
lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
sPath = String$(MAX_PATH, 0)
'Get the path from the IDList
SHGetPathFromIDList lpIDList, sPath
'free the block of memory
CoTaskMemFree lpIDList
iNull = InStr(sPath, vbNullChar)
If iNull Then
sPath = Left$(sPath, iNull - 1)
End If
End If
Verzeichnis.Text = sPath
End Sub
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP