I want to type a command in RUN or make a hyperlink to focus on a specific file (among so many files) in the folder in a highlighted figure like when you mouse over the file or when you click the "open containing folder" action in search results.



this command only opens the file, but I don't want to open it. I just want the file be selected...


I believe calling explorer with the select argument, explorer.exe /select,"C:\folder\file.xyz", should do this for you.

To use this in Excel:

Create a hyperlink referring to the same cell the link is in:

enter image description here

Then in the VBA editor, add this to the Sheet containing the hyperlink:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$E$3" Then
    Shell "explorer.exe /select,""C:\Users\Jonno\Documents\Test\New folder\Test.xlsx""", vbNormalFocus
End If

End Sub

enter image description here

Clicking it will then open an explorer window with a file highlighted. You can change this to use the value in the cell as a file if needed, or when you click any hyperlink they're handled the same way by removing the IF statement.

  • For reference: Command-Line Switches for Windows Explorer – Hexaholic Feb 15 '16 at 13:03
  • Thanks a lot for your working answer, this method solved my problem to some extend, but it is not useful when using as a hyperlink.(e.g. in Excel,...) – Alireza_frm Feb 16 '16 at 5:29
  • @Alireza_frm You could use VBA and the Shell command to launch an external program with the arguments. – Jonno Feb 16 '16 at 5:33
  • would you give me an example, please? – Alireza_frm Feb 16 '16 at 6:38
  • @Alireza_frm Added an example. – Jonno Feb 16 '16 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.