Page 1 of 1

Close DOS window

Posted: 14 May 2017 15:44
by TipMark
I have some DOS commands that run (backup files) and then the last command is to open an
Excel file.

What happens is the DOS window stays open (in the background) and when the Excel file is closed
the DOS window finally closes on its own.

Is it possible to have the DOS window close automatically, right after the Excel file open command is issued?

After the file open command I have 'Exit'.

Re: Close DOS window

Posted: 14 May 2017 15:59
by ShadowThief
Sure, just add && exit /b to the line where you call the Excel file. For instance,

Code: Select all

@echo off
pause
start "" excel.exe && exit /b

Re: Close DOS window

Posted: 15 May 2017 16:02
by TipMark
ShadowThief wrote:Sure, just add && exit /b to the line where you call the Excel file. For instance,

Code: Select all

@echo off
pause
start "" excel.exe && exit /b


Thanks Shadow. I just tried out your code and am not getting the results I hoped for.

This is my line to open the file (before adding your code):

"c:\Program Files\MS Office yada yada....\excel.exe" d:\Mom\2017.xls

If I add your code (&& exit /b):
1. at end of my code, there is no effect.
2. in the middle, it then asks to confirm each file overwrite,
is not opening the Excel file (but opening Excel) and not closing window!
3. at beginning after excel.exe, it closes window but doesn't open the Excel file.

Re: Close DOS window

Posted: 15 May 2017 16:16
by aGerman
Because you didn't use the START command Excel was run synchronoulsy. That should have been the reason why the batch window didn't close. Thus, I don't think you would even need EXIT /B. However you still need to run Excel asynchronously using START.

Code: Select all

start "" "excel.exe" "d:\Mom\2017.xls"

Don't omit the empty pair of quotation marks at the beginning.

Steffen

Re: Close DOS window

Posted: 15 May 2017 17:32
by TipMark
aGerman wrote:Because you didn't use the START command Excel was run synchronoulsy. That should have been the reason why the batch window didn't close. Thus, I don't think you would even need EXIT /B. However you still need to run Excel asynchronously using START.

Code: Select all

start "" "excel.exe" "d:\Mom\2017.xls"

Don't omit the empty pair of quotation marks at the beginning.

Steffen


Thanks Steffen. Well I think I am making progress. :)

I tried the start "" suggestion.
The window is closing now but another unexpected behavior has surfaced.
Excel is opening with a pop-up for a password (as is normal for this file).
BUT... even with the cursor blinking in the field waiting for a password to be entered,
I can't enter anything in the box!

I must first click on the border of the box, before it will allow me to enter a password!

This is happening with a shortcut I created on the desktop to launch the .bat file.

If I launch the .bat file from Total Commander, the DOS window pops up, runs a few commands and disappears.
Then, Total Commander remains on top of the Excel program that launched.
When I close Total Commander, the password field is ready to accept a password.

I hope this is clear.

It will be desirable to run the .bat file from the desktop, have the Excel password field pop-up and be ready to accept the password immediately.

Re: Close DOS window

Posted: 09 Jun 2017 15:12
by carlsomo
TipMark,

Assuming you wish to run some batch code and then, when finished start a specific excel spreadsheet and have the batch window closed with the excel window 'on top' ??

You could try this:

RunMyBatchThenOpenMyExcelFile.bat (make a shortcut to this file and set to run minimized under shortcut properties)

Code: Select all

@echo off
call MyBatchCodeFile.bat &rem run your batch code in a visible cmd window
start "" "excel.exe" "d:\Mom\2017.xls"


Sorry to hear about Foxidrive, a very good contributer....

Carl