wincc按钮excel表格怎么是空的 点击:355 | 回复:1



ttccyy

    
  • 精华:0帖
  • 求助:16帖
  • 帖子:36帖 | 19回
  • 年度积分:0
  • 历史总积分:126
  • 注册:2008年11月14日
发表于:2014-07-11 11:10:49
楼主

wincc6.2,在线表格,旁用一按钮,单机按钮,保存打印excel表格,写了vb脚本,但是单机按钮表格是空的不知哪里有问题?excel表格事先做好样式,这样式有什么特别做法吗还是随便填写文字?样式表格放在C盘,但是单机按钮excel表格就保持在E盘了。

Sub OnLButtonDown(ByVal Item, ByVal Flags,ByVal x, ByVal y)    

Dim objExcelApp,objExcelBook,objexcelsheet

Dim m1

Dim m2

Dim m3

Dim m4

Dim i,j

Dim tagshijian,sheetname,username

Dim msg

Set m1 = HMIRuntime.Tags("motor")

Set m2 = HMIRuntime.Tags("tan")

Set m3 =HMIRuntime.Tags("motor_actual")

Set m4 =HMIRuntime.Tags("TankLevel")

Set username =HMIRuntime.Tags("@CurrentUserName")

msg="ok"

sheetname="sheetdemo"

On Error Resume Next

Dim ExcelApp,ExcelBook

SetExcelApp=GetObject(,"Excel.Application")

IfTypeName(ExcelApp)="Application" Then

For Each ExcelBook In ExcelApp.WorkBooks

IfExcelBook.FullName="C:\book1.xls" Then

ExcelApp.ActiveWorkbook.Save

ExcelApp.Workbooks.Close

ExcelApp.Quit

Set ExcelApp=Nothing

Exit For

End If

Next

End If

SetobjExcelApp=CreateObject("Excel.Application")

objExcelApp.Visible=True

objExcelApp.Workbooks.Open"C:\book1.xls"

objExcelApp.Worksheets(sheetname).Activate

With objExcelApp.Worksheets(sheetname)

For i=5 To 30

For j=1 To 5

.cells(i,j)=Null

Next

Next

For i=31 To 31

For j=1 To 4

.cells(i,j)=Null

Next

Next

End With

tagshijian=Now

objExcelApp.Worksheets(sheetname).cells(2,2).value=tagshijian

username.Read

objExcelApp.Worksheets(sheetname).cells(2,5).value=username.Value

For i=5 To 30

with objExcelApp.Worksheets(sheetname)

.cell(i,1).value=tagshijian

m1.Read

.cell(i,2).value=m1.Value

m2.Read

.cell(i,3).value=m2.Value

m3.Read

.cell(i,4).value=m3.Value

m4.Read

.cell(i,5).value=m4.Value

End With

Next

MsgBox msg

Dim patch,filename

filename=CStr(Year(Now))&CStr(Month(Now))&CStr(Day(Now))+CStr(Hour(Now))&CStr(Minute(Now))

patch="E:\"&filename&".xls"

objExcelApp.ActiveWorkbook.SaveAs patch

objExcelApp.Workbooks.Close

objExcelApp.Quit

Set objExcelApp=Nothing

End Sub





未来战士_40

  • 精华:1帖
  • 求助:0帖
  • 帖子:48帖 | 55回
  • 年度积分:1
  • 历史总积分:241
  • 注册:2002年10月21日
发表于:2015-01-14 10:34:15
1楼

http://item.taobao.com/item.htm?id=43198823353

这个应该可以解决你的问题


热门招聘
相关主题

官方公众号

智造工程师