It's a bit of a silly question, but how do you close a folder through Excel VBA ? Below the code to opening it,
Shell "Explorer.exe \\sharepoint.com@SSL\DavWWWRoot\sites\folder", vbMinimizedFocus
This solution with the process ID unfortunately does not work.
The following code loops through all opened Explorer windows. So you can use that to match against the
LocationURL
and get the window handlehWnd
and use Windows APISendMessage
to close the window.Note that the
LocationURL
path begins withfile://
and that all backslashes\
in the path are converted to slashes/
as shown in the example.To make it compatible with both 64 and 32 bit Excel you can use
Note that one of these will be marked in red as compile error but the code will still run.