browse button in input box to find file Excel2007

2019-08-13 07:30发布

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.

2条回答
forever°为你锁心
2楼-- · 2019-08-13 08:03

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

查看更多
Explosion°爆炸
3楼-- · 2019-08-13 08:15

Alternately:

Sub tgr()

    Dim strFilePath As String

    strFilePath = Application.GetOpenFilename
    If strFilePath = "False" Then Exit Sub  'Pressed cancel

    MsgBox strFilePath

End Sub
查看更多
登录 后发表回答