How to code a batch file?

E

Eric

Does anyone have any suggestions on how to code a batch file to open an excel
file if current time is between 9 am and 10 am? otherwise don't open it.
Thanks in advance for any suggestions
Eric
 
D

David H. Lipman

From: "Eric" <[email protected]>

| Does anyone have any suggestions on how to code a batch file to open an excel
| file if current time is between 9 am and 10 am? otherwise don't open it.
| Thanks in advance for any suggestions
| Eric

Use Task Scheduler to open the XLS file during that time period.
 
J

John John - MVP

Eric said:
Does anyone have any suggestions on how to code a batch file to open an excel
file if current time is between 9 am and 10 am? otherwise don't open it.
Thanks in advance for any suggestions

Here you go:

=======================================================================
@echo off
for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)
if /i %tm% LSS 900 goto eof
if /i %tm% GTR 1000 goto eof
"x:\Data Folder\FileName.xls"

=======================================================================

John
 
E

Eric

Thank everyone very much for suggestions
Could you please give me any suggestions on how to add following condition
into batch file?
If (today is tuesday or wednesday or thursday or friday) and current time is
between 9 am to 10 am then
open D:/file.xls
Do you have any suggestions?
Thank everyone very much for any suggestions
Eric
 
J

John John - MVP

Eric said:
Thank everyone very much for suggestions
Could you please give me any suggestions on how to add following condition
into batch file?
If (today is tuesday or wednesday or thursday or friday) and current time is
between 9 am to 10 am then
open D:/file.xls
Do you have any suggestions?
Thank everyone very much for any suggestions


If you only want to open a file on Friday and on no other day:

======================================================================
@echo off
for /f "tokens=1 delims=/.- " %%A in ('echo %date%') do (set day=%%A)
for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)
if /i %tm% LSS 900 goto eof
if /i %tm% GTR 1000 goto eof
if /i %day%==fri goto friday
goto :eof

:friday
"D:/file1.xls"

======================================================================



If you want to open different files based on day or the week:

======================================================================
@echo off
for /f "tokens=1 delims=/.- " %%A in ('echo %date%') do (set day=%%A)
for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)
if /i %tm% LSS 900 goto eof
if /i %tm% GTR 1400 goto eof
if /i %day%==sun goto sunday
if /i %day%==mon goto monday
if /i %day%==tue goto tuesday
if /i %day%==wed goto wednesday
if /i %day%==thu goto thursday
if /i %day%==fri goto friday
if /i %day%==sat goto saturday

:sunday
"D:/file1.xls"
goto :eof

:monday
"D:/file2.xls"
goto :eof

:tuesday
"D:/file3.xls"
goto :eof

:wednesday
"D:/file4.xls"
goto :eof

:thursday
"D:/file5.xls"
goto :eof

:friday
"D:/file6.xls"
goto:eof

:saturday
"D:/file7.xls"

======================================================================

John
 
J

John John - MVP

PS:

The command window will stay open (minimized to the taskbar). You can
use the START command to avoid this, example:

====================================================================
@echo off
for /f "tokens=1 delims=/.- " %%A in ('echo %date%') do (set day=%%A)
for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)
if /i %tm% LSS 900 goto eof
if /i %tm% GTR 1000 goto eof
if /i %day%==fri goto friday
goto :eof

:friday
start "C:\Program Files\Lotus\123\123w.exe" "E:\123DATA\PAYROLL.123"

=======================================================================

John
 
E

Eric

I finished the rest code on the other day, does it look right?
Thank everyone very much for any suggestions
Eric

======================================================================
@echo off
for /f "tokens=1 delims=/.- " %%A in ('echo %date%') do (set day=%%A)
for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)
if /i %tm% LSS 900 goto eof
if /i %tm% GTR 1000 goto eof
if /i %day%==tue goto tuesday
if /i %day%==wed goto wednesday
if /i %day%==thu goto thursday
if /i %day%==fri goto friday
goto :eof

:tuesday
:wednesday
:thursday
:friday
"D:/file1.xls"

======================================================================
 
D

David H. Lipman

From: "Eric" <[email protected]>

| Thank everyone very much for suggestions
| Could you please give me any suggestions on how to add following condition
| into batch file?
| If (today is tuesday or wednesday or thursday or friday) and current time is
| between 9 am to 10 am then
| open D:/file.xls
| Do you have any suggestions?
| Thank everyone very much for any suggestions
| Eric

Again...

Use the system Task Scheduler !

No programming logic needed -- KISS !
 
D

David H. Lipman

From: "Eric" <[email protected]>

| I finished the rest code on the other day, does it look right?
| Thank everyone very much for any suggestions
| Eric

This is too funny...

Writing a BAT file for this is like swatting a fly with a sledge hammer.

The Task Scheduler is the easiest approach as *IT* will automatically do what you want at
a given time on a given day!
 
B

BillyBob

David H. Lipman said:
From: "Eric" <[email protected]>

| I finished the rest code on the other day, does it look right?
| Thank everyone very much for any suggestions
| Eric

This is too funny...

Writing a BAT file for this is like swatting a fly with a sledge hammer.

The Task Scheduler is the easiest approach as *IT* will automatically do
what you want at
a given time on a given day!

Dave,

Don't get yourself agitated. Eric is a moron that cannot follow simple
instructions. He multiposts all over the place. Read PA Bear's post above.
Check the microsoft.public.excel.programming NG and search 'Eric'.

Apparently, Eric has the mind of a houseplant and the mentality of a stepped
on potato chip. He needs his Thorazine dose increased dramatically or just
changed over to Risperdal. He'll post anything, anywhere as long as his
handcuffs are off. I know. I'm his doctor.

BB
 
P

Paul

David said:
From: "Eric" <[email protected]>

| Thank everyone very much for suggestions
| Could you please give me any suggestions on how to add following condition
| into batch file?
| If (today is tuesday or wednesday or thursday or friday) and current time is
| between 9 am to 10 am then
| open D:/file.xls
| Do you have any suggestions?
| Thank everyone very much for any suggestions
| Eric

Again...

Use the system Task Scheduler !

No programming logic needed -- KISS !

"KISS" even has its own article :)

http://en.wikipedia.org/wiki/KISS_principle

Paul
 
J

John John - MVP

David said:
From: "Eric" <[email protected]>

| I finished the rest code on the other day, does it look right?
| Thank everyone very much for any suggestions
| Eric

This is too funny...

Writing a BAT file for this is like swatting a fly with a sledge hammer.

The Task Scheduler is the easiest approach as *IT* will automatically do what you want at
a given time on a given day!

But keep in mind that the scheduled task will run at the designated time
on the designated day whether you need to run it or not, and that it may
open files whether you want to work on them or not, or whether you are
at the computer or not. With the batch file you can run this at your
own time, like at 9:45 instead of 9:00, or not at all if there is
nothing to do with the file.

John
 
J

John John - MVP

Eric said:
I finished the rest code on the other day, does it look right?

No, you put the labels :)tuesday, :wednesday...) but you didn't put any
commands under the labels (except for the :friday label) and you didn't
put a goto at the end of the labels so the batch file will keep on
processing down the list of labels regardless of the day of the week.
Also, being that you're opening the same file ("D:/file1.xls")
regardless of the day so you can shorten the batch file with one label
only, try this instead:


======================================================================
@echo off
for /f "tokens=1 delims=/.- " %%A in ('echo %date%') do (set day=%%A)
for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)
if /i %tm% LSS 900 goto eof
if /i %tm% GTR 1000 goto eof
if /i %day%==tue goto openfile
if /i %day%==wed goto openfile
if /i %day%==thu goto openfile
if /i %day%==fri goto openfile
goto :eof

:blush:penfile
"D:/file1.xls"

======================================================================

John
 
P

PA Bear [MS MVP]

BillyBob said:
Dave,

Don't get yourself agitated. Eric is a moron that cannot follow simple
instructions. He multiposts all over the place. Read PA Bear's post
above.
Check the microsoft.public.excel.programming NG and search 'Eric'.

Apparently, Eric has the mind of a houseplant and the mentality of a
stepped
on potato chip. He needs his Thorazine dose increased dramatically or
just
changed over to Risperdal. He'll post anything, anywhere as long as his
handcuffs are off. I know. I'm his doctor.

Screenwipes, please.

Paging Nurse Ratchet...
 
E

Eric

Thanks a lot for suggestions
Eric

John John - MVP said:
No, you put the labels :)tuesday, :wednesday...) but you didn't put any
commands under the labels (except for the :friday label) and you didn't
put a goto at the end of the labels so the batch file will keep on
processing down the list of labels regardless of the day of the week.
Also, being that you're opening the same file ("D:/file1.xls")
regardless of the day so you can shorten the batch file with one label
only, try this instead:


======================================================================
@echo off
for /f "tokens=1 delims=/.- " %%A in ('echo %date%') do (set day=%%A)
for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)
if /i %tm% LSS 900 goto eof
if /i %tm% GTR 1000 goto eof
if /i %day%==tue goto openfile
if /i %day%==wed goto openfile
if /i %day%==thu goto openfile
if /i %day%==fri goto openfile
goto :eof

:blush:penfile
"D:/file1.xls"

======================================================================

John
.
 

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