Excel VBA Open and close a Folder

2019-09-04 08:45发布

So I know how to open a folder within an excel vba macro, but I want to be able to close it as well. Any thoughts? This is what I'm using to open the folder:

Shell "Explorer.exe *file path*"

1条回答
Deceive 欺骗
2楼-- · 2019-09-04 09:05

You can use the Process ID, stored in vPID, to kill the application when you’re done with it. all you have to do is invoke the TaskKill command with the same Shell function.

Dim vPID As Variant
vPID = Shell "Explorer.exe *file path*"

'Perform actions here

'// Kill file
Call Shell("TaskKill /F /PID " & CStr(vPID))
查看更多
登录 后发表回答