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

后端 未结 12 784
面向向阳花
面向向阳花 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:58

    I think this is the simplest way to get to what you want.

    Credit to JMK's answer for the first part, and the hyperlink part was adapted from http://msdn.microsoft.com/en-us/library/office/ff822490(v=office.15).aspx

    'Gets the entire path to the file including the filename using the open file dialog
    Dim filename As String
    filename = Application.GetOpenFilename
    
    'Adds a hyperlink to cell b5 in the currently active sheet
    With ActiveSheet
     .Hyperlinks.Add Anchor:=.Range("b5"), _
     Address:=filename, _
     ScreenTip:="The screenTIP", _
     TextToDisplay:=filename
    End With
    

提交回复
热议问题