简体   繁体   中英

Open Windows Explorer using Excel VBA referencing path and a cell formula

I'm having problems opening a folder designated by a path and a cell

Private Sub cmd_OPEN_FOLDER_Click()

    Dim d As String
    Dim FolderPath As String
    Dim FinalFolder As String

    FolderPath = "C:\Users\USER1\Desktop\ExampleFolder1\ExampleFolder2\"

    FinalFolder = "ActiveSheet.Range(N1).Value" & "\"

    Call Shell("explorer.exe """ & FolderPath & FinalFolder & "", vbNormalFocus)

End Sub

If I omit,

FinalFolder = "ActiveSheet.Range(N1).Value" & "\"

and change,

Call Shell("explorer.exe """ & FolderPath & FinalFolder & "", vbNormalFocus)

to,

Call Shell("explorer.exe """ & FolderPath & "", vbNormalFocus)

it works. But if I add 'FinalFolder'. It opens MyDocuments folder. I guess its a default when something isn't working?

Cell N1 has a formula which references another cell on a different sheet. The Formula is "=LISTS.A4". This sheet is hidden.

You need to refer to

"ActiveSheet.Range(N1).Value"

as

ActiveSheet.Range("N1").Value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM