Help with Shell command - using a variable path

Brian_in_Austin

New Member
Joined
Feb 26, 2016
Messages
2
Hi,

I want to be open Windows Explorer and select (but not open) a specified file (like a show in folder command). The file is on a USB drive and I'm asking the user to enter the drive letter in a cell.
Cell D1: Drive Letter. Example: E
Cell E1: Folder: Example: \MyVideos\
And the activecell has the name of the file to search for.

I found this Shell command (below) from GlennFromIowa, and it works great. However, I want to use the values in cells D1 and E1 rather than the hardwired "D:\username\documents\workplans\" in the example. How would I change the Shell command?

Thanks!!!!

<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">Sub open_explorer()
Shell
"C:\Windows\explorer.exe /select, D:\username\Documents\workplans\"& ActiveCell.Value, vbMaximizedFocus
EndSub</code>
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Code:
Sub open_explorer()
Shell "C:\Windows\explorer.exe /select, " & [D1].Value & ":\" & [E1].Value & "\" & ActiveCell.Value, vbMaximizedFocus
End Sub
 
Last edited:
Upvote 0
Code:
Sub open_explorer()
Shell "C:\Windows\explorer.exe /select, " & [D1].Value & ":\" & [E1].Value & "\" & ActiveCell.Value, vbMaximizedFocus
End Sub

TY TY TY!!!

P.S. Because cell E1 has the value \MyVideos\ I changed your code to this:
Shell "C:\Windows\explorer.exe /select, " & [D1].Value & ":" & [E1].Value & ActiveCell.Value, vbMaximizedFocus
 
Upvote 0

Forum statistics

Threads
1,215,263
Messages
6,123,958
Members
449,135
Latest member
jcschafer209

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top