18. august 2007 - 17:22Der er
8 kommentarer og 2 løsninger
GetOpenFilename skal acceptere mappevalg
Jeg mangler en kode til at kunne vælge en mappe, frem for en fil. Altså at jeg med Application.GetOpenFilename eller lignende åbn dialogboks kan vælge en mappe, og klikke "Gem".
Filer i mappe skal nok ikke kunne vises, da det ikke er et filvalg, men et mappevalg det drejer sig om.
I dette særtema om aspekter af AI ser vi på skiftet fra sprogmodeller til AI-agenter, og hvordan virksomheder kan navigere i spændet mellem teknologisk hastighed og behovet for menneskelig kontrol.
For hulen, da. Har ledt i ugevis, og finder nu denne:
Option Explicit 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
'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
Sub Test() Dim Msg As String Msg = "Please select a location for the backup." MsgBox GetDirectory(Msg) End Sub
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 = "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 If End Function
Sub Test() Dim Msg As String Msg = "Please select a location for the backup." MsgBox GetDirectory(Msg) End Sub
NOTE: If you use Excel 2002 you can prompt the user to select a directory by using the new FileDialog object. The advantage is that you can specify a starting directory.
Public Sub minMakro() Dim MinSti As String MinSti = UseFileDialogOpen MsgBox MinSti End Sub
Function UseFileDialogOpen() As String ' Open the file dialog With Application.FileDialog(msoFileDialogFolderPicker) .AllowMultiSelect = False .Show UseFileDialogOpen = .SelectedItems(1) End With End Function
Function UseFileDialogOpen() As String ' Open the file dialog On Error GoTo Slut With Application.FileDialog(msoFileDialogFolderPicker) .AllowMultiSelect = False .Show .InitialFileName = "C:\" UseFileDialogOpen = .SelectedItems(1) End With Exit Function Slut: UseFileDialogOpen = "Du valgte intet bibliotek" Err.Clear End Function
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.