建立一个模本excel文件d:\ExcelExample.xls
wincc里创建内部变量i,无符号32位
在全局脚本vb创建两个动作
1、复制另存ExcelExample.xls,并改名为当天日期,触发周期为1天,i被赋值为2
Option Explicit
Function action
Dim fso,myfile,daystr,dstr,fname
dstr = FormatDateTime(Date)
fname="d:\" + dstr + ".xls"
Set fso = CreateObject("s cripting.FileSystemObject")
Set MyFile = fso.GetFile("d:\ExcelExample.xls")
MyFile.Copy (fname)
HMIRuntime.Tags("i").write 2
End Function
2、往当天的excel文件里写数据,并保存
Option Explicit
Function action
Dim fso,myfile,daystr,dstr,fname
dstr = FormatDateTime(Date)
fname="d:\" + dstr + ".xls"
Dim ObjExcelApp
Set objExcelApp = CreateObject("Excel.Application")
objExcelApp.Workbooks.Open fname
Dim i
HMIRuntime.Tags("i").write HMIRuntime.Tags("i").Read+1
i=HMIRuntime.Tags("i").Read
objExcelApp.worksheets ("sheet1").Cells(i, 2).VAlue = HMIRuntime.Tags("I-COD").read
objExcelApp.worksheets ("sheet1").Cells(i, 3).VAlue = HMIRuntime.Tags("I-SS").read
objExcelApp.worksheets ("sheet1").Cells(i, 4).VAlue = HMIRuntime.Tags("I-PH").read
objExcelApp.worksheets ("sheet1").Cells(i, 5).VAlue = HMIRuntime.Tags("I-F").read
objExcelApp.worksheets ("sheet1").Cells(i, 6).VAlue = HMIRuntime.Tags("I-FI").read
objExcelApp.worksheets ("sheet1").Cells(i, 7).VAlue = HMIRuntime.Tags("O-COD").read
objExcelApp.worksheets ("sheet1").Cells(i, 8).VAlue = HMIRuntime.Tags("O-SS").read
objExcelApp.worksheets ("sheet1").Cells(i, 9).VAlue = HMIRuntime.Tags("O-NH4N").read
objExcelApp.worksheets ("sheet1").Cells(i, 10).VAlue = HMIRuntime.Tags("0-P").read
objExcelApp.worksheets ("sheet1").Cells(i, 11).VAlue = HMIRuntime.Tags("O-F").read
objExcelApp.worksheets ("sheet1").Cells(i, 12).VAlue = HMIRuntime.Tags("O-FI").read
objExcelApp.worksheets ("sheet1").Cells(i, 1).VAlue =Now
objExcelApp.ActiveWorkbook.Save
objExcelApp.Workbooks.ClosE
objExcelApp.QuiT
Set ObjEXceLapp = Nothing
End Function
问题:怎么在退出wincc时,保存i的值,使wincc再激活时,向excel最后位置写数据
注:从wincc帮助抄的程序