|
View Full Version : Is there a dos command to close an excel worksheet ?
Emory Richter 10-30-2005, 03:50 PM In XP,
Is there a dos command to close an excel worksheet
not the excel application ?
I can find nothing on google.
I have tried the utility "pv"
C:\Windows\Command\pv -k -f file.xls
but that will close only processes
and file.xls is listed in Task Manager applications.
Thank you,
Emory
Clay Calvert 10-31-2005, 11:11 PM On Sun, 30 Oct 2005 10:50:32 -0500, Emory Richter <none@none.com>
wrote:
>In XP,
>Is there a dos command to close an excel worksheet
>not the excel application ?
This one-liner worked for me. Use single percent signs if run from
the command line. As is it is written for batch. This uses only
tools built into XP.
for /f "tokens=2" %%a in ('tasklist /v ^|findstr /i /i /C:"file.xls"')
do taskkill /PID %%a
Cheers,
Clay Calvert
CCalvert@Wanguru.com
Replace "W" with "L"
Emory Richter 11-01-2005, 05:44 PM In article <gl8dm15mqmrrcj2qqjime6fu9s0mp1en5j@4ax.com>,
ccalvert@Wanguru.com says...
> On Sun, 30 Oct 2005 10:50:32 -0500, Emory Richter <none@none.com>
> wrote:
>
> >In XP,
> >Is there a dos command to close an excel worksheet
> >not the excel application ?
>
> This one-liner worked for me.
> for /f "tokens=2" %%a in ('tasklist /v ^|findstr /i /i /C:"file.xls"')
> do taskkill /PID %%a
Clay, thanks for your response.
But, I am a novice
and the method of using this
seems beyond me.
Emory
Clay Calvert 11-02-2005, 02:52 AM On Tue, 1 Nov 2005 12:44:58 -0500, Emory Richter <none@none.com>
wrote:
>> This one-liner worked for me.
>> for /f "tokens=2" %%a in ('tasklist /v ^|findstr /i /i /C:"file.xls"')
>> do taskkill /PID %%a
>
>Clay, thanks for your response.
>But, I am a novice
>and the method of using this
>seems beyond me.
The only thing you really need to change is the file name.
Actually, I was writing up how this works when I saw a simpler way to
do this.
taskkill /FI "WindowTitle eq Microsoft Excel - file.xls"
Clay Calvert
CCalvert@Wanguru.com
Replace "W" with "L"
Emory Richter 11-03-2005, 05:25 PM In article <df9gm1la3s0j464j04l2v0jk7hs5q87rru@4ax.com>,
ccalvert@Wanguru.com says...
>> On Tue, 1 Nov 2005 12:44:58 -0500, Emory Richter wrote:
>
> Actually, I was writing up how this works when I saw a simpler way to
> do this.
>
> taskkill /FI "WindowTitle eq Microsoft Excel - file.xls"
Clay,
in XP with SP2
with other worksheets open and also WatchLists.xls open
when I try:
taskkill /FI "WindowTitle eq Microsoft Excel - WatchLists.xls"
I get:
ERROR: Invalid Argument/Option - 'WatchLists.xls'.
The title is right according to the Excel title bar.
As other worksheets are open
the Task Manager shows the title as only 'WatchLists.xls'.
but when I try:
taskkill /FI "WindowTitle eq WatchLists.xls"
I get:
INFO: No tasks running with the specified criteria.
I have also tried other variations eg:
taskkill /F /FI "WindowTitle eq Microsoft Excel - WatchLists.xls"
etc.
but always the error message appears.
Thank you for your past help and - any suggestions ?
Emory
Clay Calvert 11-04-2005, 09:56 PM On Thu, 3 Nov 2005 12:25:25 -0500, Emory Richter <none@none.com>
wrote:
>Clay,
>in XP with SP2
>with other worksheets open and also WatchLists.xls open
>when I try:
>taskkill /FI "WindowTitle eq Microsoft Excel - WatchLists.xls"
>I get:
>ERROR: Invalid Argument/Option - 'WatchLists.xls'.
>
>The title is right according to the Excel title bar.
>As other worksheets are open
>the Task Manager shows the title as only 'WatchLists.xls'.
>but when I try:
>taskkill /FI "WindowTitle eq WatchLists.xls"
>I get:
>INFO: No tasks running with the specified criteria.
>
>I have also tried other variations eg:
>taskkill /F /FI "WindowTitle eq Microsoft Excel - WatchLists.xls"
>etc.
>but always the error message appears.
>
>Thank you for your past help and - any suggestions ?
Interesting. I was able to replicate your scenario. It looks like
only one instance of Excel is running, even though two Excel items are
on the TaskBark. I just noticed that even though there are two items
on the taskbar, there is really only one Excel window open.
This VBscript worked for me, YMMV.
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "Microsoft Excel - Katherine's Family tree.xls"
WScript.Sleep 1000
WshShell.SendKeys "^w"
WScript.Sleep 2500
You can test the first timeout value, but I'd leave the bottom one
alone.
VBscript can only send keys to the active window. I believe
higher-end languages can send to windows if they know the 'handle'.
HTH
Clay Calvert
CCalvert@Wanguru.com
Replace "W" with "L"
Emory Richter 11-05-2005, 03:06 PM In article <6oknm19vlti7mmbcnaata0s62il1d73v82@4ax.com>,
ccalvert@Wanguru.com says...
>> On Thu, 3 Nov 2005 12:25:25 -0500, Emory Richter <none@none.com>
>> wrote:
> This VBscript worked for me, YMMV.
>
> set WshShell = WScript.CreateObject("WScript.Shell")
> WshShell.AppActivate "Microsoft Excel - Katherine's Family tree.xls"
> WScript.Sleep 1000
> WshShell.SendKeys "^w"
> WScript.Sleep 2500
>
It worked as a .vbs file for me also.
Clay, thanks for your effort on this question.
Emory
Clay Calvert 11-06-2005, 08:26 PM On Sat, 5 Nov 2005 10:06:18 -0500, Emory Richter <none@none.com>
wrote:
>It worked as a .vbs file for me also.
>Clay, thanks for your effort on this question.
>Emory
Great, and I got a little education in the process. ; )
Cheers
Clay Calvert
CCalvert@Wanguru.com
Replace "W" with "L"
|
|
|