Option Explicit
Function action
Dim objExcelAPP
Dim reportfile
Dim reportfile1
Dim reporttime
Dim index
Dim j
Dim i
index=Hour(Now)
index=CInt(index)
reportfile=CStr(Date)
reporttime=Hour(Now)
reporttime=CStr(reporttime)
reportfile=reportfile
reportfile1=reportfile
reportfile="D:\report\" & reportfile & ".xls"
Dim TEMP_1
Set TEMP_1 = HMIRuntime.Tags("TEMP_1")
Dim TEMP_2
Set TEMP_2 = HMIRuntime.Tags("TEMP_2")
Dim TEMP_3
Set TEMP_3 = HMIRuntime.Tags("TEMP_3")
Dim TEMP_4
Set TEMP_4 = HMIRuntime.Tags("TEMP_4")
Dim TEMP_5
Set TEMP_5 = HMIRuntime.Tags("TEMP_5")
Dim TEMP_6
Set TEMP_6 = HMIRuntime.Tags("TEMP_6")
Dim TEMP_7
Set TEMP_7 = HMIRuntime.Tags("TEMP_7")
Dim TEMP_8
Set TEMP_8 = HMIRuntime.Tags("TEMP_8")
Dim TEMP_9
Set TEMP_9 = HMIRuntime.Tags("TEMP_9")
Dim flow_1
Set flow_1 = HMIRuntime.Tags("flow_1")
Dim flow_2
Set flow_2 = HMIRuntime.Tags("flow_2")
Dim reportname
Set reportname = HMIRuntime.Tags("reportname")
TEMP_1.Read
TEMP_2.Read
TEMP_3.Read
TEMP_4.Read
TEMP_5.Read
TEMP_6.Read
TEMP_7.Read
TEMP_8.Read
TEMP_9.Read
flow_1.Read
flow_2.Read
Set objExcelAPP=CreateObject("Excel.Application")
objExcelAPP.Visible=False
objExcelAPP.Workbooks.Open "D:\report\book1.xls"
With objExcelAPP
If index=0 Then
For i=5 To 28
For j= 2 To 12
.cells(i,j).value=Null
Next
Next
.cells(2,2).value=Date
End If
j=0
j=index+5
.cells(j,2).value=TEMP_1.Value
.cells(j,3).value=TEMP_2.Value
.cells(j,4).value=TEMP_3.Value
.cells(j,5).value=TEMP_4.Value
.cells(j,6).value=TEMP_5.Value
.cells(j,7).value=TEMP_6.Value
.cells(j,8).value=TEMP_7.Value
.cells(j,9).value=TEMP_8.Value
.cells(j,10).value=TEMP_9.Value
.cells(j,11).value=flow_1.Value
.cells(j,12).value=flow_2.Value
If index=23 Then
''.cells(30,3).value=FY1901ACC2.Value
''.cells(30,5).value=FY1901ACC1.Value
''.cells(30,8).value=FT1908ACC2.Value
''.cells(30,10).value=FT1908ACC1.Value
.ActiveWorkbook.SaveAs reportfile
reportname.Write reportfile1
Else
.ActiveWorkbook.Save
End If
.ActiveWorkbook.Close
.Quit
End With
Set objExcelAPP=Nothing
End Function
现希望做报表归档,实现定时记录。这是一段往EXCEL表格写变量值的VB程序,如果希望没8分钟记录一次 我该怎么修改?
最佳答案
建一个全局变量保存上次归档时间和系统当前时间比较即可
提问者对于答案的评价:
0
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc277420.html