Sub X6309X94AE4X0000T_OnLButtonDown(Byval Item, Byval Flags, Byval x, Byval y)
Dim g_excelfilename
Dim excel
g_excelfilename ="E:\Excel.xls"
Set excel = CreateObject("Excel.Application")
excel.Visible = True
excel.Workbooks.Open g_excelfilename
objexcelapp.ActiveWorkBook.worksheets("sheet1").cells(4,3).value.Value=HMIRuntime.Tags("temprature").Read
excel.ActiveWorkbook.Save
objexcelapp.workbooks.close
objexcelapp.quit
Set objexcelapp=Nothing
End Sub
用脚本调试器调试时发现在点击按钮后:
能打开excel表格,但执行到objexcelapp时出现,变量未定义:'objexcelapp' 请问是什么原因?
后来我有在程序头定义了objexcelapp 出现缺少该对象,哪里除了问题,往指教
最佳答案
Set excel = CreateObject("Excel.Application")
这个语句中的“EXCEL”变量才是你定义的EXCEL对象
而你定义了EXCEL对象后,后面却使用了OBJEXCELAPP这个对象名,和上面已经定义的那个变量名根本没有关系,因此出错的这句应该改为EXCEL.ACTIVEWORKBOOK.worksheets("sheet1").cells
另外一个问题,就是1楼提到的,ceLL.value.value怎么写了两个VALUE.
Dim g_excelfilename as string
Dim WinccExcel As Excel.Application
Set WinccExcel=CreateObject("Excel.Application")
g_excelfilename ="E:\Excel.xls"
winccexcel.Visible = True
winccexcel.Workbooks.Open g_excelfilename
winccexcel.ActiveWorkBook.worksheets("sheet1").cells(4,3).value=HMIRuntime.Tags("temprature").Read
winccexcel.ActiveWorkbook.Save
winccexcel.workbooks.close
winccexcel.quit
Set winccexcel=Nothing
提问者对于答案的评价:
谢谢
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc276694.html