问题
I need the browse button in input box to find file - VB A - EXCEL Macro][1]
need to find the folder path via browse button instead of typing in input box is it possible?
|-------------------|
|-------------------| Browse by clicking a cell it should ask for file browse. should not be edited manually. i mean , i want to lock the particular cell locked. and only able to edit via macro.
回答1:
Alternately:
Sub tgr()
Dim strFilePath As String
strFilePath = Application.GetOpenFilename
If strFilePath = "False" Then Exit Sub 'Pressed cancel
MsgBox strFilePath
End Sub
回答2:
You can use this to find a file. Modify the filter if you need to. the variable fldr
will have your data. Then you can set your textbox to that value.
Sub File_Picker()
With Application.FileDialog(msoFileDialogFilePicker)
.Filters.Clear
.Filters.Add "Text", "*.txt", 1
.InitialFileName = ActiveWorkbook.Path & "\"
.Show
If .SelectedItems.Count = 0 Then GoTo 1
fldr = .SelectedItems(1)
End With
End Sub
or:
Sub Folder_Picker()
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = ActiveWorkbook.Path & "\"
.Show
If .SelectedItems.Count = 0 Then GoTo 1
fldr = .SelectedItems(1)
End With
End Sub
I have more helpful pieces of code like this at My GitHub
来源:https://stackoverflow.com/questions/18358964/browse-button-in-input-box-to-find-file-excel2007-vba