wincc excel
刘玉蓉
发布于2014-10-17 16:52
63
0
标签:
按照资料上的例子,做了这样一个程序,添加的for和if语句后,不能执行,而且excel打开了,关闭不了。
目的是打开excel后,先判断将要写入的位置是否为空,如果为空,则将io域的值写入,如果不为空,查看下一行是否为空,一直到为空的时候写入io域的值。
图片说明: 1,程序
佳答案
两个同样的问题,这是找答案的缺陷,同一问题提出后只有一次补充说明的机会。
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