ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Close Shell (https://www.excelbanter.com/excel-programming/415003-close-shell.html)

BigPig

Close Shell
 
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.

Gary''s Student

Close Shell
 
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

--
Gary''s Student - gsnu200797


"BigPig" wrote:

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.


Rick Rothstein \(MVP - VB\)[_2456_]

Close Shell
 
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


"BigPig" wrote in message
...
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.



BigPig

Close Shell
 
Gary''s Student,

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

BigPig

Close Shell
 
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.


All times are GMT +1. The time now is 02:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com