| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
Reworld,下班在家制作游戏,1500万奖金等你拿以码会友 以友辅仁
共有 471 人关注过本帖
标题:我是搞自控的,wincc用到VBS脚本,打印一个表格,请帮我翻译一下,这个代码 ...
只看楼主 加入收藏
yuanzhihang
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2019-7-7
结帖率:0
  已结贴   问题点数:20  回复次数:10   
我是搞自控的,wincc用到VBS脚本,打印一个表格,请帮我翻译一下,这个代码啥意思
Option Explicit
Function action

Dim oExcel,filename,c
Select Case Hour(Now())
Case 0  c=Hour(Now())+12
        filename="d:\报表\二网报表\"&Year(Date())&"年"&Month(Date())&"月"& Day(Date())&"日.xlsx"
        Set oExcel = CreateObject("Excel.Application")
            oExcel.displayalerts=False
            oExcel.Visible =False  
            oExcel.WorkBooks.Open("d:\报表\二网报表模板.xlsx" )
            oExcel.Workbooks(1).Activate
            oExcel.workbooks(1).SaveAs filename
            oExcel.quit
        Set oExcel=Nothing
Case 1  c=Hour(Now())+12
Case 2  c=Hour(Now())+12
Case 3  c=Hour(Now())+12
Case 4  c=Hour(Now())+12
Case 5  c=Hour(Now())+12
Case 6  c=Hour(Now())+12
Case 7  c=Hour(Now())+12
Case 8  c=Hour(Now())+12
Case 9  c=Hour(Now())+12
Case 10  c=Hour(Now())+12
Case 11  c=Hour(Now())+12
Case 12  c=Hour(Now())+12
Case 13  c=Hour(Now())+12
Case 14  c=Hour(Now())+12
Case 15  c=Hour(Now())+12
Case 16  c=Hour(Now())+12
Case 17  c=Hour(Now())+12
Case 18  c=Hour(Now())+12
Case 19  c=Hour(Now())+12
Case 20  c=Hour(Now())+12
Case 21  c=Hour(Now())+12
Case 22  c=Hour(Now())+12
Case 23  c=Hour(Now())+12
End Select
Set oExcel = CreateObject("Excel.Application")
oExcel.displayalerts=False
oExcel.Visible =False  
oExcel.WorkBooks.Open("d:\报表\二网报表\"&Year(Date())&"年"&Month(Date())&"月"& Day(Date())&"日.xlsx" )
oExcel.Workbooks(1).Activate
oExcel.Cells(c,2).Value = HMIRuntime.Tags("PT_101_3").Read
oExcel.Cells(c,3).Value = HMIRuntime.Tags("PT_101_4").Read
oExcel.Cells(c,4).Value = HMIRuntime.Tags("PT_201_4").Read
oExcel.Cells(c,5).Value = HMIRuntime.Tags("PT_301_4").Read
oExcel.Cells(c,6).Value = HMIRuntime.Tags("PT_101_6").Read
oExcel.Cells(c,7).Value = HMIRuntime.Tags("PT_107_6").Read
oExcel.Cells(c,8).Value = HMIRuntime.Tags("PT_101_7").Read
oExcel.Cells(c,9).Value = HMIRuntime.Tags("PT_101_8").Read
oExcel.Cells(c,10).Value = HMIRuntime.Tags("PT_102_3").Read
oExcel.Cells(c,11).Value = HMIRuntime.Tags("PT_102_4").Read
oExcel.Cells(c,12).Value = HMIRuntime.Tags("PT_202_4").Read
oExcel.Cells(c,13).Value = HMIRuntime.Tags("PT_102_6").Read
oExcel.Cells(c,14).Value = HMIRuntime.Tags("PT_108_6").Read
oExcel.Cells(c,15).Value = HMIRuntime.Tags("PT_102_7").Read
oExcel.Cells(c,16).Value = HMIRuntime.Tags("PT_102_8").Read
oExcel.Cells(c,17).Value = HMIRuntime.Tags("PT_302_4").Read
oExcel.Cells(c,18).Value = HMIRuntime.Tags("TE_101_3").Read
oExcel.Cells(c,19).Value = HMIRuntime.Tags("TE_101_4").Read
oExcel.Cells(c,20).Value = HMIRuntime.Tags("TE_201_4").Read
oExcel.Cells(c,21).Value = HMIRuntime.Tags("TE_301_4").Read
oExcel.Cells(c,22).Value = HMIRuntime.Tags("TE_101_6").Read
oExcel.Cells(c,23).Value = HMIRuntime.Tags("TE_107_6").Read
oExcel.Cells(c,24).Value = HMIRuntime.Tags("TE_101_7").Read
oExcel.Cells(c,25).Value = HMIRuntime.Tags("TE_101_8").Read
oExcel.Cells(c,26).Value = HMIRuntime.Tags("TE_106_3").Read
oExcel.Cells(c,27).Value = HMIRuntime.Tags("TE_107_3").Read
oExcel.Cells(c,28).Value = HMIRuntime.Tags("TE_102_4").Read
oExcel.Cells(c,29).Value = HMIRuntime.Tags("TE_202_4").Read
oExcel.Cells(c,30).Value = HMIRuntime.Tags("TE_302_4").Read
oExcel.Cells(c,31).Value = HMIRuntime.Tags("TE_102_6").Read
oExcel.Cells(c,32).Value = HMIRuntime.Tags("TE_108_6").Read
oExcel.Cells(c,33).Value = HMIRuntime.Tags("TE_106_7").Read
oExcel.Cells(c,34).Value = HMIRuntime.Tags("TE_107_7").Read
oExcel.Cells(c,35).Value = HMIRuntime.Tags("TE_102_8").Read
oExcel.Cells(c,36).Value = HMIRuntime.Tags("").Read
oExcel.Cells(c,37).Value = HMIRuntime.Tags("TE_001_8L").Read
oExcel.Cells(c,38).Value = HMIRuntime.Tags("").Read
oExcel.Cells(c,39).Value = HMIRuntime.Tags("TE_101_11").Read
oExcel.Cells(c,40).Value = HMIRuntime.Tags("TE_102_11").Read
oExcel.Cells(c,41).Value = HMIRuntime.Tags("TE_101_10").Read
oExcel.Cells(c,42).Value = HMIRuntime.Tags("TE_102_10").Read
oExcel.Cells(c,43).Value = HMIRuntime.Tags("TE_101_13").Read
oExcel.Cells(c,44).Value = HMIRuntime.Tags("TE_101_9").Read
oExcel.Cells(c,45).Value = HMIRuntime.Tags("TE_101_12").Read
oExcel.Cells(c,46).Value = HMIRuntime.Tags("FT_002_3").Read
oExcel.Cells(c,47).Value = HMIRuntime.Tags("FT_003_3").Read
oExcel.Cells(c,48).Value = HMIRuntime.Tags("FT_002_4").Read
oExcel.Cells(c,49).Value = HMIRuntime.Tags("FT_201_4").Read
oExcel.Cells(c,50).Value = HMIRuntime.Tags("FT_301_4").Read
oExcel.Cells(c,51).Value = HMIRuntime.Tags("FT_101_6").Read
oExcel.Cells(c,52).Value = HMIRuntime.Tags("FT_103_6").Read
oExcel.Cells(c,53).Value = HMIRuntime.Tags("FT_003_7").Read
oExcel.Cells(c,54).Value = HMIRuntime.Tags("FT_002_7").Read
oExcel.Cells(c,55).Value = HMIRuntime.Tags("FT_002_8").Read
oExcel.Cells(c,56).Value = HMIRuntime.Tags("TT-431/TT-431.PV_Out#Value").Read
oExcel.Cells(c,57).Value = HMIRuntime.Tags("TT-432/TT-432.PV_Out#Value").Read
oExcel.save
oExcel.quit
Set oExcel=Nothing


End Function
搜索更多相关主题的帖子: Case 报表 Date Value Read 
2019-07-07 21:12
yuanzhihang
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2019-7-7
  得分:0 
附件: 您没有浏览附件的权限,请 登录注册
2019-07-07 21:14
yuanzhihang
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2019-7-7
  得分:0 
上面是表格,
2019-07-07 21:15
wmf2014
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:185
帖 子:1799
专家分:10092
注 册:2014-12-6
  得分:10 
这大概就是传说中的屎代码吧。

能编个毛线衣吗?
2019-07-07 22:30
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:260
帖 子:4434
专家分:27297
注 册:2008-10-15
  得分:10 
看起来像,特别是那个多分支选择。

Option Explicit
Function action            

Dim oExcel,filename,c
Select Case Hour(Now())         以当前小时数为选择条件
Case 0  c=Hour(Now())+12        0点,
        filename="d:\报表\二网报表\"&Year(Date())&"年"&Month(Date())&"月"& Day(Date())&"日.xlsx"
        Set oExcel = CreateObject("Excel.Application")
            oExcel.displayalerts=False
            oExcel.Visible =False  
            oExcel.WorkBooks.Open("d:\报表\二网报表模板.xlsx" )       打开模板
            oExcel.Workbooks(1).Activate
            oExcel.workbooks(1).SaveAs filename                       保存为 当天报表
            oExcel.quit
        Set oExcel=Nothing
Case 1  c=Hour(Now())+12            时间数+12,垃圾写法。
Case 2  c=Hour(Now())+12
Case 3  c=Hour(Now())+12
Case 4  c=Hour(Now())+12
Case 5  c=Hour(Now())+12
Case 6  c=Hour(Now())+12
Case 7  c=Hour(Now())+12
Case 8  c=Hour(Now())+12
Case 9  c=Hour(Now())+12
Case 10  c=Hour(Now())+12
Case 11  c=Hour(Now())+12
Case 12  c=Hour(Now())+12
Case 13  c=Hour(Now())+12
Case 14  c=Hour(Now())+12
Case 15  c=Hour(Now())+12
Case 16  c=Hour(Now())+12
Case 17  c=Hour(Now())+12
Case 18  c=Hour(Now())+12
Case 19  c=Hour(Now())+12
Case 20  c=Hour(Now())+12
Case 21  c=Hour(Now())+12
Case 22  c=Hour(Now())+12
Case 23  c=Hour(Now())+12
End Select
----------
Set oExcel = CreateObject("Excel.Application")
oExcel.displayalerts=False
oExcel.Visible =False  
oExcel.WorkBooks.Open("d:\报表\二网报表\"&Year(Date())&"年"&Month(Date())&"月"& Day(Date())&"日.xlsx" ) 打开报表
oExcel.Workbooks(1).Activate
oExcel.Cells(c,2).Value = HMIRuntime.Tags("PT_101_3").Read            把数据一个格子一个格子的填进去。
oExcel.Cells(c,3).Value = HMIRuntime.Tags("PT_101_4").Read
oExcel.Cells(c,4).Value = HMIRuntime.Tags("PT_201_4").Read
oExcel.Cells(c,5).Value = HMIRuntime.Tags("PT_301_4").Read
oExcel.Cells(c,6).Value = HMIRuntime.Tags("PT_101_6").Read
oExcel.Cells(c,7).Value = HMIRuntime.Tags("PT_107_6").Read
oExcel.Cells(c,8).Value = HMIRuntime.Tags("PT_101_7").Read
oExcel.Cells(c,9).Value = HMIRuntime.Tags("PT_101_8").Read
oExcel.Cells(c,10).Value = HMIRuntime.Tags("PT_102_3").Read
oExcel.Cells(c,11).Value = HMIRuntime.Tags("PT_102_4").Read
oExcel.Cells(c,12).Value = HMIRuntime.Tags("PT_202_4").Read
oExcel.Cells(c,13).Value = HMIRuntime.Tags("PT_102_6").Read
oExcel.Cells(c,14).Value = HMIRuntime.Tags("PT_108_6").Read
oExcel.Cells(c,15).Value = HMIRuntime.Tags("PT_102_7").Read
oExcel.Cells(c,16).Value = HMIRuntime.Tags("PT_102_8").Read
oExcel.Cells(c,17).Value = HMIRuntime.Tags("PT_302_4").Read
oExcel.Cells(c,18).Value = HMIRuntime.Tags("TE_101_3").Read
oExcel.Cells(c,19).Value = HMIRuntime.Tags("TE_101_4").Read
oExcel.Cells(c,20).Value = HMIRuntime.Tags("TE_201_4").Read
oExcel.Cells(c,21).Value = HMIRuntime.Tags("TE_301_4").Read
oExcel.Cells(c,22).Value = HMIRuntime.Tags("TE_101_6").Read
oExcel.Cells(c,23).Value = HMIRuntime.Tags("TE_107_6").Read
oExcel.Cells(c,24).Value = HMIRuntime.Tags("TE_101_7").Read
oExcel.Cells(c,25).Value = HMIRuntime.Tags("TE_101_8").Read
oExcel.Cells(c,26).Value = HMIRuntime.Tags("TE_106_3").Read
oExcel.Cells(c,27).Value = HMIRuntime.Tags("TE_107_3").Read
oExcel.Cells(c,28).Value = HMIRuntime.Tags("TE_102_4").Read
oExcel.Cells(c,29).Value = HMIRuntime.Tags("TE_202_4").Read
oExcel.Cells(c,30).Value = HMIRuntime.Tags("TE_302_4").Read
oExcel.Cells(c,31).Value = HMIRuntime.Tags("TE_102_6").Read
oExcel.Cells(c,32).Value = HMIRuntime.Tags("TE_108_6").Read
oExcel.Cells(c,33).Value = HMIRuntime.Tags("TE_106_7").Read
oExcel.Cells(c,34).Value = HMIRuntime.Tags("TE_107_7").Read
oExcel.Cells(c,35).Value = HMIRuntime.Tags("TE_102_8").Read
oExcel.Cells(c,36).Value = HMIRuntime.Tags("").Read
oExcel.Cells(c,37).Value = HMIRuntime.Tags("TE_001_8L").Read
oExcel.Cells(c,38).Value = HMIRuntime.Tags("").Read
oExcel.Cells(c,39).Value = HMIRuntime.Tags("TE_101_11").Read
oExcel.Cells(c,40).Value = HMIRuntime.Tags("TE_102_11").Read
oExcel.Cells(c,41).Value = HMIRuntime.Tags("TE_101_10").Read
oExcel.Cells(c,42).Value = HMIRuntime.Tags("TE_102_10").Read
oExcel.Cells(c,43).Value = HMIRuntime.Tags("TE_101_13").Read
oExcel.Cells(c,44).Value = HMIRuntime.Tags("TE_101_9").Read
oExcel.Cells(c,45).Value = HMIRuntime.Tags("TE_101_12").Read
oExcel.Cells(c,46).Value = HMIRuntime.Tags("FT_002_3").Read
oExcel.Cells(c,47).Value = HMIRuntime.Tags("FT_003_3").Read
oExcel.Cells(c,48).Value = HMIRuntime.Tags("FT_002_4").Read
oExcel.Cells(c,49).Value = HMIRuntime.Tags("FT_201_4").Read
oExcel.Cells(c,50).Value = HMIRuntime.Tags("FT_301_4").Read
oExcel.Cells(c,51).Value = HMIRuntime.Tags("FT_101_6").Read
oExcel.Cells(c,52).Value = HMIRuntime.Tags("FT_103_6").Read
oExcel.Cells(c,53).Value = HMIRuntime.Tags("FT_003_7").Read
oExcel.Cells(c,54).Value = HMIRuntime.Tags("FT_002_7").Read
oExcel.Cells(c,55).Value = HMIRuntime.Tags("FT_002_8").Read
oExcel.Cells(c,56).Value = HMIRuntime.Tags("TT-431/TT-431.PV_Out#Value").Read
oExcel.Cells(c,57).Value = HMIRuntime.Tags("TT-432/TT-432.PV_Out#Value").Read
oExcel.save       保存报表
oExcel.quit       退出EXECE
Set oExcel=Nothing   释放变量

授人于鱼,不如授人于渔
早已停用QQ了
2019-07-07 23:08
yuanzhihang
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2019-7-7
  得分:0 
回复 5楼 风吹过b
非常感谢,真的是醍醐灌顶,昨天一直发愁,今天早早醒了,看了你的回复,清晰明了,非常感谢
2019-07-08 07:01
yuanzhihang
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2019-7-7
  得分:0 
回复 4楼 wmf2014
我是搞PLC的,看了5楼的回复搞明白以后,才明白你的意思,真的像在织毛衣,太形象了
2019-07-08 07:03
yuanzhihang
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2019-7-7
  得分:0 
回复 5楼 风吹过b
请问,如果以当前分钟为时间选择怎么修改,我是小白,请详细解释一下怎么修改,谢谢!
2019-07-08 07:19
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:260
帖 子:4434
专家分:27297
注 册:2008-10-15
  得分:0 
Now()  返回当前日期+时间
Hour   返回指定时间里的小时数
Minute 返回分钟数
Second  返回秒数
Year   返回年数
Month  返回月数
Day    返回天数

你现在用的是  hour ,是按小时,按分钟,使用 Minute 函数。

授人于鱼,不如授人于渔
早已停用QQ了
2019-07-08 12:33
yuanzhihang
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2019-7-7
  得分:0 
回复 9楼 风吹过b
跪求回答,这个程序有个BUG,每次保存总是另存为,程序该怎么改?
2019-07-10 22:16
快速回复:我是搞自控的,wincc用到VBS脚本,打印一个表格,请帮我翻译一下,这个 ...
数据加载中...
 
   





关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.079301 second(s), 8 queries.
Copyright©2004-2019, BCCN.NET, All Rights Reserved