资源描述:
《程序有几处不懂,请帮忙注释一下》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、程序有几处不懂,请帮忙注释一下 ‘先定义变量 DimobjExcelApp,objExcelBook,objExcelSheet Dimtagyali1,tagyali2,tagyali3,tagyali4 Dimtagliuliang1,tagliuliang2 Dimtago2 Dimtagshijian,sheetname Dimi,j Dimmsg ‘声明 Settagyali1=HMIRuntime.Tags(“MicroWin.fu程序有几处不懂,请帮忙注释一下 ‘先定义变量 Di
2、mobjExcelApp,objExcelBook,objExcelSheet Dimtagyali1,tagyali2,tagyali3,tagyali4 Dimtagliuliang1,tagliuliang2 Dimtago2 Dimtagshijian,sheetname Dimi,j Dimmsg ‘声明 Settagyali1=HMIRuntime.Tags(“MicroWin.fuyang.v.p1”) Settagyali2=HMIRuntime.Tags(“MicroWin.fuy
3、ang.v.p2”) Settagyali3=HMIRuntime.Tags(“MicroWin.fuyang.v.p3”) Settagyali4=HMIRuntime.Tags(“MicroWin.fuyang.v.p4”) Settagliuliang1=HMIRuntime.Tags(“MicroWin.fuyang.v.l1”) Settagliuliang2=HMIRuntime.Tags(“MicroWin.fuyang.v.lt2”) Settago2=HMIRuntime.Tags(“Mi
4、croWin.fuyang.v.o2”) msg=“ok” sheetname=“sheet1” ‘判断是否打开了模版,如果打开先关闭保存 OnErrorResumeNext DimExcelApp,ExcelBook SetExcelApp=GetObject(,”Excel.Application”) IfTypeName(ExcelApp)=“Application”Then ForEachExcelBookInExcelApp.WorkBooks IfExcelBook.FullName=“
5、E:iao.xls”Then ExcelApp.ActiveWorkbook.Save ExcelApp.Workbooks.Close ExcelApp.Quit SetExcelApp=Nothing ExitFor EndIf Next EndIf ‘创建对象 SetobjExcelApp=CreateObject(“Excel.Application”) openfile objExcelApp.Visible=True objExcelApp.Workbooks.Open”E:
6、iao.xls” objExcelApp.Worksheets(sheetname).Activate ‘清除模版数据 WithobjExcelApp.Worksheets(sheetname) Fori=5To25 Forj=1To8 .cells(i,j)=Null Next Next Fori=26To26 Forj=1To7 .cells(i,j)=Null Next Next EndWith ‘实时数据写入 tagshijian=Now objExcelApp.Worksh
7、eets(sheetname).cells(2,2).value=tagshijian Fori=5To25 withobjExcelApp.Worksheets(sheetname) .cell(i,1).value=tagshijian tagyali1.Read .cell(i,2).value=tagyali1.value tagyali2.Read .cell(i,3).value=tagyali2.value tagyali3.Read .cell(i,4).value=tagyali3
8、.value tagyali4.Read .cell(i,5).value=tagyali4.value tagliuliang1.Read .cell(i,6).value=tagliuliang1.value tagliuliang2.Read .cell(i,7).value=tagliuliang2.value tago2