简体   繁体   中英

Excel vba open folder using same instance of explorer.exe

I was using following code in excel vba

returnval = Shell("explorer.exe " & folderPath, vbNormalFocus)

to open folders, this works fine but it starts a new process of windows explorer. Now 2 windows explorer processes are visible in task manager. If I keep using this function with different folderPath it creates a new instance of explorer processes every time.

How can i use existing explorer.exe instance to open folder from excel vba?

Try full path of explorer.exe . For example you should use C:\\WINDOWS\\explorer.exe instead of explorer.exe. This works for me.

Instead of shell, ThisWorkbook has follow hyperlink which will open any file/url with the default app. It doesn't open another process of explorer.exe for me.

ThisWorkbook.FollowHyperlink "C:\filepath"

If you really need to use shell, then you'll have to call cmd.exe then start like this:

returnval = Shell("cmd.exe /c start filepath")

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