各位大神,最近几天在研究WinCC的报表,想要制作制作一个能够将数据写入excel的报表,参见下载中心的A0300_WinCC数据报表实现方法介绍的VBS脚本,进行了一定的修改,但是一直都没有反应,也没有输出对应的excel文件,我反复查找都不知道问题出在哪,各位能帮忙看下吗?
Sub OnLButtonUp(ByVal Item, ByVal Flags, ByVal x, ByVal y)
Dim objExcelAPP,objExcelBook,objExcelSheet
Dim tagmushu
Dim tagshijian,sheetname,username
Dim i,j
Dim msg
'shengming
Set tagmushu=HMIRuntime.Tags("mushu")
Set username=HMIRuntime.Tags("@CurrentUserName")
Msg="OK"
Sheetname="sheetdemo"
'panduan
On Error Resume Next
Dim ExcelApp,ExcelBook
Set ExcelApp=GetObject(,"Excel.Application")
If TypeName(ExcelApp)="Application" Then
For Each ExcelBook In ExcelApp.WorkBooks
If ExcelBook.FullName="E:\XY_TEST\SWJ\SG_WINCC_TEST\excelreport\production_data.xls" Then
ExcelApp.ActiveWorkbook.Save
ExcelApp.Workbooks.close
ExcelApp.Quit
Set ExcelApp=Nothing
Exit For
End If
Next
End If
'chuangjian
Set objExcelApp=CreatObject("Excel.Application")
'open file
objExcelApp.Visble=True
objExcelApp.Workbooks.Open"E:\XY_TEST\SWJ\SG_WINCC_TEST\excelreport\production_data.xls"
objExcelApp.Worksheets(sheetname).Activate
'qingchu
With objExcelApp.Worksheets(sheetname)
For i=5 To 25
For j=1 To 2
.cell(i,j)=Null
Next
Next
End With
'xieru
tagshijian=Now
objExcelApp.Worksheets(sheetname).cells(2,2).value=tagshijian
username.Read
objExcelApp.Worksheets(sheetname).cells(2,3).value=username.Read
For i=5 To 25
With objExcelApp.Worksheets(sheetname)
.cells(i,1).value=tagshijian
tagmushu.Read
.cells(i,2).value=tagmushu.Read
End With
Next
MsgBox msg
'guanbi
Dim patch,filename
filename=CStr(Year(Now))&CStr(Month(Now))&CStr(Day(Now))&CStr(Hour(Now))&CStr(Minute(Now))
patch="E:\XY_TEST\SWJ\SG_WINCC_TEST\excelreport\"&filename&"demo.xls"
objExcelApp.ActiveWorkbook.SaveAS patch
objExcelApp.Workbooks.Close
objExcelApp.Quit
Set objExcelApp=Nothing
End Sub
由于刚开始弄,所以现在简单的是想把数据实时的写入excel,后续的想做成触发式的写入,诸位高手,能给小弟个指点么?我刚玩WinCC不久,先谢谢诸位了!