批处理文件跟踪信息并使用vba打开外部excel 2010文件

时间:2015-10-27 15:35:38

标签: batch-file

我正在编写一个batch文件,当它运行时会捕获Windows登录,日期和时间。我想在batch中放置一个计数器,用于跟踪批处理文件是否被打开,如果第二个问题(粗体)的答案是" y"则递增1。如果计数器为= 1,则会显示一条消息,其中包含用户名,日期和时间(斜体)。如果任何一个问题的答案是" n"那么"再见"显示,batch关闭。我收到语法错误,需要一些帮助。谢谢 :)。

新批处理文件

@ECHO OFF
:: ask user 
:choice
set /P c=Has the check been done [y/n]
if /i %c%==y (
set /P c=Do you want to send the DOSE report[y/n]?
) 
:: count loop
set var1=0
:loop
set /a var1=%var1%+1
if %var1% EQU 1 (
goto :end
) else (
goto :loop
)
:end
echo "the DOSE report has already been sent by %USERNAME% on %DATE% at %TIME%"
else if /i not %c% ==n goto goodbye
if /i %c%==y ( 
"L:\NGS\HLA LAB\total quality management\QC & QA\DOSE reports\DOSE reporting form.xlsm"
) else if /i not %c%==n goto goodbye
:goodbye
echo "Goodbye"
TIMEOUT 2 /nobreak
exit
end

屏幕上的当前显示

1
"the DOSE report has already been sent by cmccabe on Tue 10/27/2015 at   11:00:20.
21"
Has the check been done [y/n]

1 个答案:

答案 0 :(得分:1)

我不太了解您对程序的描述,但我很擅长批处理文件的特定格式和语法。我执行这样的代码时没有收到语法错误。

@ECHO OFF
:: count loop
set var1=0
:loop
set /a var1=%var1%+1

echo %var1%

if %var1% EQU 1 (
    goto end
) else (
    goto loop
)
:end
echo "the DOSE report has already been sent by %USERNAME% on %DATE% at   %TIME%"

:: ask user 
:choice
set /P c=Has the check been done [y/n]
if /i %c%==y (
    set /P c=Do you want to send the DOSE report[y/n]?
) else (
    if /i %c%==n goto goodbye
)
if /i %c%==y ( 
    ECHO "L:\NGS\HLA LAB\total quality management\QC & QA\DOSE reports\DOSE reporting    form.xlsm"
) else (
    if /i %c%==n goto goodbye
)
:goodbye
echo "goodbye"
pause