大侠给看看错在哪里了?wincc excel

按照资料上的例子,做了这样一个程序,添加的for和if语句后,不能执行,而且excel打开了,关闭不了。
目的是打开excel后,先判断将要写入的位置是否为空,如果为空,则将i\o域的值写入,如果不为空,查看下一行是否为空,一直到为空的时候写入i\o域的值。

图片说明:

大侠给看看错在哪里了?wincc excel   

最佳答案

两个同样的问题,这是找答案的缺陷,同一问题提出后只有一次补充说明的机会。
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

提问者对于答案的评价:
你好,我把下面的程序放在按钮的鼠标中执行,出现的结果是,按一下,打开一次excel文件“zmx02.xls”,而且全是可以看到的,后面打开的全是只读文件,单元格的数据也没有改变,请看一看,是什么问题。谢谢你。
Sub OnLButtonDown(ByVal Item, ByVal Flags, ByVal x, ByVal y)    
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:\zmx02.xls"
If HMIRuntime.Tags("zmxw01").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("zmxw01").read
objExcelApp.ActiveWorkbook.Save
objExcelApp.Workbooks.Close
objExcelApp.Quit
Set objExcelApp = Nothing


End Sub

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

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

相关推荐