title image

Smiley Re: Suche API Aufruf, um einen Verzeichnissdialog anzuzeigen.
Hallo,Ich denke das folgende Beispiel muesste Dir weiterhelfen koennen.Ist zwar (nur) fuer VBA und funktioniert in Excel97.Hab's irgendwann mal im Web gefunden.Viele GruesseNorbertxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxIf your Excel application needs to prompt the user for a directory, you may have been surprised to discover that there is no direct way to do this. You can use the GetOpenFileName method to display a dialog that prompts for a file name, but there is no way to display a dialog box that shows only directories. In this document I present a function (named GetDirectory) that displays the dialog box shown below, and returns a string that represents the selected directory. If the user clicks cancel, the function returns an empty string. The GetDirectory function takes one argument, which is optional. This argument is a string that will be displayed in the dialog box. If the argument is omitted, the dialog box displays Select a folder as the message. NOTE: This function uses the 32-bit API, so it works only with Excel 95 or Excel 97. It will not work with 16-bit Excel 5. The GetDirectory functionThe GetDirectory function is listed below. To use this function, copy the text and paste it to a VBA module. Option ExplicitPublic 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 LongEnd Type'32-bit API declarationsDeclare Function SHGetPathFromIDList Lib "shell32.dll" _ Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As LongDeclare Function SHBrowseForFolder Lib "shell32.dll" _Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As LongSub Test() Dim Msg As String Msg = "Please select a location for the backup." MsgBox GetDirectory(Msg)End SubFunction 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 = "Select a folder." 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$(0)) GetDirectory = Left(path, pos - 1) Else GetDirectory = "" End IfEnd FunctionUsing the functionThe simple subroutine listed below demonstrates how to use the GetDirectory function in your code. Executing this subroutine displays the dialog box. When the user clicks OK or Cancel, the MsgBox function displays the full path of the selected directory. Sub Test() Dim Msg As String Msg = "Please select a location for the backup." MsgBox GetDirectory(Msg)End Sub

geschrieben von




Beitrag anfügen