发布于 2006-03-09 09:58:05
0楼
第一段:
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)
End Function
第二段:
Option Explicit
Function action
Dim fso,myfilep,daystr,dstr,fname
Set fso = CreateObject("s cripting.FileSystemObject")
dstr = FormatDateTime(Date)
HMIRuntime.Tags("i").write fso.GetAbsolutePathName("")
fname=HMIRuntime.ActiveProject.Path++dstr+.xls
Dim ObjExcelApp
Set objExcelApp = CreateObject("Excel.Application")
objExCelApp.Visible = True
objExcelApp.Workbooks.Open fname
Dim i
i=1
Do While objExcelApp.worksheets ("sheet1").Cells(i, 1).VAlue<>""
i=i+1
Loop
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
其中objExCelApp.Visible = True可以去掉,就是后台操作了
这两段程序分别是两个动作
第一段的触发周期是一天,作用是复制另存ExcelExample.xls,并改名为当天日期
第二段是忘当天的excel文件里写数据的,触发周期根据个人情况,测试时可以定为10秒,就是每10秒写一次数据
另外第二段里的HMIRuntime.Tags都是我wincc里的变量,要根据自己的情况修改
我找到了,但是启动的时候并没有在d盘找到ExcelExample.xls啊。
第一个动作就不成功
还有就是wincc6.0触发周期定义为:“每日的”下面是“xx小时xx分xx秒”
这个我写的是0:0:01
不是每启动一次就运行吗?
避风塘http://arong.blog.com.cn