‘ vbs 113 示例如何实现循环

wincc中 ” vbs113示例为从wincc i\o 域 写入excel 单元格的例子程序,现在我想实现写入单元格的循环,也就是第一个数据写入第一行,第二个数据写入第二行,请问,如何用vbs实现。

问题补充:
你好:看了你的回帖。
现在补充如下:
我现在的想法是要将cells(1,3),改为cells(i,j),分别对i和j进行循环取值。
同时通过if then设置条件。
现在不明白的是:这些语句加在哪里?

最佳答案

重新弄了一下,用next for跳转出去
Dim objExcelApp,i,j
Set objExcelApp = CreateObject("Excel.Application")
objExcelApp.Visible = True
”ExcelExample.xls is to create before executing this procedure.
”Replace <path> with the real path of the file ExcelExample.xls.
objExcelApp.Workbooks.Open "d:\dd.xls"
If HMIRuntime.Tags("NewTag_14").read=1 Then

For i=1 To 10

If objExcelApp.worksheets("sheet1").Cells(i,1).VAlue ="" Then
j=i
Exit For 
End If
Next

End If
objExcelApp.worksheets("sheet1").Cells(j,1).VAlue =HMIRuntime.Tags("NewTag_14").read
objExcelApp.ActiveWorkbook.Save
objExcelApp.Workbooks.Close
objExcelApp.Quit
Set objExcelApp = Nothing

提问者对于答案的评价:
O(∩_∩)O谢谢,我先学习学习,再看行不行。

原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc264656.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2019年6月11日
下一篇 2019年6月11日

相关推荐