Here is a hackish approach using SendKeys
that will work if the open instance of explorer.exe
has the focus:
Set WshShell = WScript.CreateObject("WScript.Shell")
target = "C:/programs"
WshShell.SendKeys "%d"
WshShell.SendKeys target
WshShell.SendKeys "{ENTER}"
This will work if you e.g. have the above code (with the intended target) in a script in one folder. Click on the script icon and it will send you to the target folder.
[On Edit] An explanation of how it works: If you are using Windows Explorer and type Alt+d
(which is what SendKeys "%d"
simulates) then the focus is shifted to the address bar. For years I have been using this trick to open a command prompt in the current folder (Alt - d
then type cmd
then press Enter
and the prompt opens with the open folder as the working directory). When I saw this question I wondered if essentially the same trick (but automated with VBScript) would work for navigation purposes and was pleasantly surprised when it worked as intended the very first time. Alt-d
is a useful keyboard shortcut to keep in mind.