当前位置: 主页 > PLC控制

winCC里的变量,记录到excel表格中查询

我要把我wincc数据读到exCEl表格中查询,按日期、批号、品名(字符串)、产量的格式,每天在excel表格中自动保存一个sheet,只保存最新3个月数据,之前的自动删除。请问VBS脚本怎么写。寻求帮助,非常感谢!

最佳答案

DimExcelApp
DimExcelBook
DimExcelSheet

Dimi”用于检查哪一行未写入数据

Dimfso
Setfso=CreateObject("Scripting.FilESySTemObject")
Iffso.FileExists("C:\tmpProj\Model.xlsx")Then
”模板文件存在
Iffso.FileExists("C:\tmpProj\1.xlsx")Then
”今天生成的文件存在
SetExcelApp=CreateObject("Excel.Application")
SetExcelBook=ExcelApp.Workbooks.Open("C:\tmpProj\1.xlsx")
SetExcelSheet=ExcelBook.Sheets.Item("Sheet1")
”判断第几行为空
i=2”起始行为2
DoWhileExcelSheet.Cells(i,2).Value<>""
i=i+1
Loop

ExcelSheet.Cells(i,2).Value=SmaRTTags("VarUnsigned8")


ExcelBook.Save
ExcelBook.Close
ExcelApp.Quit

SetExcelBook=Nothing
SetExcelApp=Nothing
Else
”今天生成的文件不存在
SetExcelApp=CreateObject("Excel.Application")
SetExcelBook=ExcelApp.Workbooks.Open("C:\tmpProj\Model.xlsx")
SetExcelSheet=ExcelBook.Sheets.Item("Sheet1")

ExcelSheet.Cells(2,2).Value=SmartTags("VarUnsigned8")


ExcelBook.SaveAS"C:\tmpProj\1.xlsx"
ExcelBook.Close
ExcelApp.Quit

SetExcelBook=Nothing
SetExcelApp=Nothing
EndIf

Else
”模板文件不存在
MsgBox"模板文件不存在!"
EndIf

提问者对于答案的评价:
xiexie

专家置评

已阅,最佳答案正确。

  • 关注微信

猜你喜欢

微信公众号