我想做个报表,把数据在plc中做完处理后,通过wincc传到excel做的工作报表中,并按时间为自动保存,怎么做
最佳答案
'Example 1: MS Excel
'In this example, an output value from an input field is written in an Excel table.
'VBS113
Dim excelapp
Dim aa,bb,cc
Set excelapp = CreateObject("Excel.Application")
Set aa = HMIRuntime.tags("tag1")
excelapp.visible = False'True
excelapp.workbooks.open "D:\excel.xls"
bb = Now 'getcurrent_datetime()
aa.Read
MsgBox CStr(bb)
excelapp.cells(1,1).value = "rrrrrr"'111111
excelapp.cells(1,2).value = CStr(bb)
excelapp.cells(2,2).value = CStr(aa.value)
excelapp.cells(3,2).value = CInt(aa.value)
excelapp.cells(4,2).value = CSng(aa.value)
excelapp.cells(5,2).value = CDbl(aa.value)
excelapp.cells(6,2).value = CLng(aa.value)
excelapp.cells(3,3).value = ScreenItems("33").outputvalue
excelapp.cells(4,4).value = ScreenItems("35").outputvalue
cc = "D:\excel" + Mid(CStr(bb), 1, 4)+ Mid(CStr(bb), 6, 2)+ Mid(CStr(bb), 9, 2)+ Mid(CStr(bb), 12, 2)+ Mid(CStr(bb), 15, 2)+ Mid(CStr(bb), 18, 2) + ".xls"
MsgBox cc
excelapp.DisplayAlerts = False '对打开的文件,直接保存时,避免弹出对话框窗口,而是直接覆盖
excelapp.activeworkbook.saveas cc '根据当前日期时间,另存为新的文件
'excelapp.activeworkbook.save ’对打开的文件,直接保存
'excelapp.activeworkbook.saveAs "D:\excelcopy.xls" ’直接另存为新的文件
excelapp.workbooks.close
excelapp.quit
Set excelapp = Nothing
提问者对于答案的评价:
谢了
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc272156.html