输入框中的浏览按钮以查找文件 Excel2007 Vba
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18358964/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
browse button in input box to find file Excel2007 Vba
提问by Running Forward
I need the browse button in input box to find file - VB A - EXCEL Macro][1]
我需要输入框中的浏览按钮来查找文件 - VB A - EXCEL 宏][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.
|-------------------| 通过单击它应该要求文件浏览的单元格进行浏览。不应手动编辑。我的意思是,我想锁定锁定的特定单元格。并且只能通过宏进行编辑。
回答by MakeCents
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.
您可以使用它来查找文件。如果需要,请修改过滤器。变量fldr
将包含您的数据。然后您可以将文本框设置为该值。
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
我在我的 GitHub 上有更多这样的有用代码
回答by tigeravatar
Alternately:
交替:
Sub tgr()
Dim strFilePath As String
strFilePath = Application.GetOpenFilename
If strFilePath = "False" Then Exit Sub 'Pressed cancel
MsgBox strFilePath
End Sub