" vbs 113 示例如何实现循环
刘玉蓉
发布于2014-10-17 16:52
8
0
标签:
wincc中 "" vbs113示例为从wincc io 域 写入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