首页 > 解决方案 > VBA打印循环没有将整个循环写入批处理文件

问题描述

所以我在将项目打印到批处理文件时遇到了问题。我有一堆单元格,其中包含任务计划程序中任务的名称、开始日期和结束日期。我正在尝试遍历这些单元格并编写更改任务调度程序所需的相应代码行。

当我运行代码时,它只会将部分循环打印到批处理文件中。当我逐行遍历整个循环将编写的代码时,我取得了一些成功。

'loop through list creating command line for .bat
Dim i As Integer
For i = 8 To finalRow

commandLine = "ECHO hunter2| Schtasks /Change /TN """
'Scan name and concatonate
commandFragment = Cells(i, "B").Value
commandLine = commandLine & commandFragment
commandLine = commandLine & """ /SD "

'scan start date and concatonate
day = Cells(i, "E").Value
commandFragment = DayRefs(translateDay(day))
commandLine = commandLine & commandFragment
commandLine = commandLine & " /ST "

'scan start time and concatonate
commandFragment = Cells(i, "G").Value
commandLine = commandLine & commandFragment
commandLine = commandLine & " /ED "

'scan end date and concatonate
day = Cells(i, "F").Value
commandFragment = DayRefs(translateDay(day))
commandLine = commandLine & commandFragment
commandLine = commandLine & " /RI 1440"

'save completed command line to Commands
Commands(i - 6) = commandLine

Next

'open .bat for modification
Dim fnum As Variant
fnum = FreeFile()
Open AutomationFile For Output As #fnum

Print #fnum, "@ECHO"

'print commands
For i = 1 To finalRow - 6
Print #fnum, Commands(i)
Print #fnum, " "
Next

这是当前在批处理文件中吐出的内容的副本。它只是停止中排。并且当前的迭代应该有 8 个单独的项目,但它只通过 4 和 5 的一部分。

@ECHO

ECHO hunter2| Schtasks /Change /TN "Report Update Morning" /SD
07/22/2020 /ST 07:55 /ED 07/31/2020 /RI 1440

ECHO hunter2| Schtasks /Change /TN "Report Update Lunch" /SD
07/22/2020 /ST 11:55 /ED 07/31/2020 /RI 1440

ECHO hunter2| Schtasks /Change /TN "Report Update Evening" /SD
07/22/2020 /ST 17:25 /ED 07/31/2020 /RI 1440

ECHO hunter2| Schtasks /Change /TN "AA Sweep Macro Morning" /SD
07/27/2020 /ST 08:00 /ED 07/31/2020 /RI 1440

ECHO hunter2| Schtasks /Change /TN "A

标签: excelvbabatch-file

解决方案


推荐阅读