browse button in input box to find file Excel2007 Vba

浪尽此生 提交于 2020-01-05 05:40:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!