Function action
Dim fso,myfile,daystr,dstr,fname
dstr = FormatDateTime(Date,1)
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,1)
fname="d:\" + 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
还是这两段程序,调试好了。
可是第2段程序执行时,屏幕总是一闪,出现excel中数据,然后又回到wincc画面。能不能把wincc的画面显示最前,也就是向excel写数据是在幕后操作的。