How to get selected path and name of the file opened with file dialog?

后端 未结 12 774
面向向阳花
面向向阳花 2020-12-29 12:14

I need the path name and file name of the file that is opened with File Dialog. I want to show this information with a hyperlink in my worksheet.

With this code I ha

12条回答
  •  一个人的身影
    2020-12-29 12:52

    Sub GetFilePath()
    
    Set myFile = Application.FileDialog(msoFileDialogOpen)
    
    With myFile
    
    .Title = "Choose File"
    
    .AllowMultiSelect = False
    
    If .Show <> -1 Then
    
    Exit Sub
    
    End If
    
    FileSelected = Replace(.SelectedItems(1), .InitialFileName, "")
    
    End With
    
    ActiveSheet.Range("A1") = FileSelected
    
    End Sub
    

提交回复
热议问题