excel - 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
解决方案
推荐阅读
- javascript - 如何在 React 中的组件之间路由?
- visual-studio-code - VS Code 的 runSelectedText 可以在执行前获取函数或剥离部分命令吗?
- visual-studio - Blazor .net 核心引用枚举?参数不改变其值
- android - Android - 手动卸载后启动器图标不会重新出现
- c# - 当我尝试将文件从 txt 导入到 datagridview 时出现错误
- javascript - Node.js 中的路由
- wireshark - 使用 Wireshark 检查 pcap 文件:[在捕获期间限制数据包大小]
- google-cloud-platform - 使用私有 IP 将本地环境连接到 CloudSQL
- plotly - Plotly Dash 图例中的自定义标记
- python - Tornado 服务器在多进程模式下处理不平均的请求