Close Shell

B

BigPig

Hi All,

With this script I open a file:

Shell "explorer.exe " & ReNameFolder & SelectedFile

Through another script I rename the file and save it in a different folder.

Name ReNameFolder & SelectedFile As SQFolder & NewFileNm

How do I close the "Shell.." before I run the rename script?

I tried dimming Filename as variant, filename=shell... and then
filename.close or quit, but I got an object error.

Basically I want to take a file (could be a pdf, tif, or xfdl), rename it
and save it to a different folder. And don't want to have to go back and
delete it once done.

Any help or suggestions would be greatly appreciated.

Thanks.
 
G

Gary''s Student

If you just want to delete the original file, use the Kill command. If you
want to get rid of the Shell Object then:

Sub pig()
x = Shell("explorer.exe C:\Temp\third.xls")
Set x = Nothing
End Sub
 
R

Rick Rothstein \(MVP - VB\)

I don't think you can in "straight VB" as the Shell command spawns an
program independent of the program it was executed in. I guess you could use
the Windows API to find the shelled window by its title text and close it
with another API call. Before trying to construct all that, would making
your "script" (the one that shelled out to explorer.exe) wait for the
shelled out program to close (still require API function calls) and then
rename it at that point? Would that be an acceptable approach?

Rick
 
B

BigPig

Gary''s Student,

Thank you! I probably should have spent more time thinking about it.
 
B

BigPig

Hi Rick,

You're right. I guess I was just trying to get the "shell..." to close
without changing most of what I wrote. I'm going to try fso.copyfile and then
go back and kill the original file.

Thank you very much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top