close a shell of a windows explorer window

Puertorekinsam

Active Member
Joined
Oct 8, 2005
Messages
293
Greetings,

I use Shell to open a folder path because if the folder is not open, I can't 'kill' a file in it.

I want to close the folder after I'm done with the kill. I tried this:

If FileOrDirExists(Sheet2.Cells(Me.FileTypeList, 2) & "\" & Sheet2.Cells(Me.FileTypeList, 1) & "0." & FileType) Then
Call Shell("explorer.exe " & Sheet2.Cells(Me.FileTypeList, 2), vbMinimizedNoFocus)
Kill (Sheet2.Cells(Me.FileTypeList, 2) & "\" & Sheet2.Cells(Me.FileTypeList, 1) & "0." & FileType)
Close #1
End If

but the window stays open, can someone help me with closing the open window?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I don't believe it's necessary to open a folder in Windows Explorer if you want to delete a file in that folder in VBA. Why do you think it's necessary?
 
Upvote 0
Normally you would be correct. However, there is a corprate security measure that prevents a kill statement from running in the folder is not open. Don't know how it's acomplished, but if I try to kill a file from a networked drive and the folder is closed, it tells me it's a unauthorized command. But if I open the folder it seems to correct this issue.
 
Upvote 0
You just need to make sure you kill the full path

Code:
kill "C:\\replace\withyour\path.xls"
 
Upvote 0
I wish that was all. On a local drive (C:) i don't have the issue, but when dealing with a network drive, i need to have the folder open. My kill statement is fully qualified.

I just need to a way to close a windows explorer window opened with a shell statement.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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