-
writing batch files...
Any good resources out there for writing batch files ? I used DOS around the time WIN3.1 was around, but I've forgotten most of it.
Basically I need to write a batch file that would open up an XLS file (ie. C:\test\blah.xls) everytime the batch file is clicked. And as a bonus, if it can do an "if" statement to check if the XLS is already open, to close it and open it again (fresh copy will be deposited to directory every X minutes).
Thanks!
-
A good place to start is BATch file Links by Vernon Frazee.
------------------
My
Two Cents
Dennis
Visit Politalk
-
Thanks. I've been searching for a way to CLOSE an application (Excel) via command line (within the batch file). Is this possible?
-
I'm not sure there is any way (without using a third party utility program) to close a window from a batch file. It would be fairly simple to write a Visual Basic program to do what you want however.
-
I did find kill.exe to do the job, as it kills Excel nicely.
Turns out they didn't want the entire application closed though (they have other files Excel files that need to stay open. So they wanted one file (blah.xls) closed and not Excel altogether.
Can I ask if this is possible, even with VB ?
-
Hi rh71,
DOS batch files are commonly used as program managers. This means that a batch file can call a program, close it when finished, and then call another program automatically, or at the user's discretion. The DOSShell was designed specifically for that reason, and yes, DOSShell will run on Win98 machines.
As a program manager, a batch file can even be used to open and close Windows programs, but DOS is also very stingy and wants complete control of the computer in order to do so. In other words, running programs called within the batch file would have focus while the batch file is running, unless one of the called programs was provisioned to call other programs into activation. In the meantime, DOS would still have full control of the computer until the batch file is finally terminated.
A batch file can be used to open and close a program. Thus, if an Excel spreadsheet is called by a batch file, then it can also be closed by that same batch file, or by a different batch file that is called by the first batch file.
Basically what you are asking is if an Excel worksheet can be opened and then closed while another worksheet is running. This is usually performed within Excel using VBA, and no batch file would really be necessary.
Of course, I am not fully aware of your current situation, so there may be a perfectly valid reason for your wanting to do this with a batch file. The most common method would be to call a batch file into operation when opening Excel. In the Properties Dialog box is a provision for including a batch file that runs when Excel is opened.
-
Thanks for the in-depth info.
I've given up on this "project" since the person I was doing it for will just ask her manager to just go through a few extra steps manually. Neither of them really care and since that's their attitude, I'm not going to put anymore time into this.
Thanks though!
-
Sample Program Manager
Explanations and Help files have a tendency to confuse. So, I provided a heavily deactivated sample of a program manager based on a batch file. I had no internet connection at the time, and no VirtualDr to supply any answers. All the programs listed on the menu required very low amounts of memory. Typically DOS.
Maybe by seeing, you will decide that it is not so difficult, afterall...
The batch file will run, and following the prompts will lead it back to the main menu. Press Q to terminate the batch file.
Code:
@echo off
cls
cd\
c:
rem call a program
goto avant
:avant
echo.
echo.
echo.
echo.
echo ** Program Manager **
echo.
echo For
echo.
echo.
echo * * * *
echo.
echo ** ZAPPER **
echo.
echo * * * *
echo.
echo.
echo ** **
echo ** Select a program by menu **
echo ** **
echo.
echo.
pause
:gogo
echo.
echo ** ZAPPER ** ZAPPER ** ZAPPER **
echo.
echo.
echo.
echo.
echo ** ** A. ZapIt ** **
echo ** ** B. Disk Services ** **
echo ** ** C. QBasic ** **
echo ** ** D. TC-Lite ** **
echo ** ** E. Print ** **
echo ** ** F. File Services ** **
echo ** ** G. Masm611 ** **
echo ** ** H. DoS-Edit ** **
echo ** ** I. DoSShell ** **
echo ** ** Q. Quit ZAPPER ** **
echo.
echo.
echo.
echo.
echo ** ZAPPER Will Now Go To Work! **
echo.
echo.
cd\
d:
choice /c:abcdefghiq /n
if errorlevel 10 goto endit
if errorlevel 9 goto dshl
if errorlevel 8 goto ed
if errorlevel 7 goto day
if errorlevel 6 goto dt
if errorlevel 5 goto tx
if errorlevel 4 goto readit
if errorlevel 3 goto fil
if errorlevel 2 goto dsk
if errorlevel 1 goto fltrp
:dshl
cd\
c:
rem dosshell
goto gogo
:ed
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo ** NOW Activating The Dos Editer For APPEND! ** **
echo.
echo.
echo.
echo.
echo.
echo.
choice /c:yn /n /t:y,4
if errorlevel 2 goto gogo
if errorlevel 1 goto eddit
:eddit
cd\
c:
rem edit
goto gogo
:day
cd\
c:
rem assign a path
rem pwb
cd\
c:
goto gogo
:dt
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
choice /c:abcde Choose:
if errorlevel 5 goto gogo
if errorlevel 4 goto gogo
if errorlevel 3 goto gogo
if errorlevel 2 goto gogo
if errorlevel 1 goto gogo
:tx
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
cd\
c:
goto gogo
:readit
rem call a program
rem pause
cd\
c:
goto gogo
:fil
cd\
rem a:
rem assign a path
rem dir
rem pause
cd\
c:
goto gogo
:dsk
echo.
echo.
echo ** You May Now Choose Which Document To Copy To Disk **
echo.
echo.
echo ** This Provision Will Process And File A Finished **
echo ** Document For Printing Or Faxing At Another Time.
echo.
echo ** After Selecting The Document, The Screen Will Blank. **
echo ** Type The Path To The Source Trip Data, And Filename. **
echo.
echo.
echo ** A. File A Tax Document ** **
echo ** B. File Another Document ** **
echo ** C. File A Talley Sheet ** **
echo ** D. Return To Main Menu ** **
echo.
echo.
echo.
choice /c:abcd Choose:
if errorlevel 4 goto gogo
if errorlevel 3 goto dald
if errorlevel 2 goto dotd
if errorlevel 1 goto taxd
:taxd
cd\
c:
rem call a program
goto gogo
:dotd
cd\
c:
rem call a program
goto gogo
:dald
cd\
c:
rem call a program to open a document
goto gogo
:fltrp
rem call a program
cd\
c:
goto gogo
:endit
cls
echo.
echo.
echo.
echo.
echo ** GoodBye! ** Goodbye! ** Goodbye! **
echo.
echo.
echo.
echo.
echo.
echo.
choice /c:yn /n /t:n,4
if errorlevel 2 goto fini
if errorlevel 1 goto gogo
:fini
cd\
c: