vbs自动生成excel报表问题 点击:411 | 回复:1



smecta_aust

    
  • 精华:0帖
  • 求助:2帖
  • 帖子:2帖 | 2回
  • 年度积分:0
  • 历史总积分:28
  • 注册:2012年8月18日
发表于:2013-01-14 11:39:55
楼主

貌似无法生成,请大神指点一二


Dim bit1

Set bit1 = HMIRuntime.Tags("bit1")
HMIRuntime.Trace"Value:" &bit1.Read(1)&vbCrLf

Dim ch4_1
Set ch4_1 = HMIRuntime.Tags("ch4_1")
HMIRuntime.Trace"Value:" &ch4_1.Read(1)&vbCrLf

Dim ch4_2
Set ch4_2 = HMIRuntime.Tags("ch4_2")
HMIRuntime.Trace"Value:" &ch4_2.Read(1)&vbCrLf

Dim wendu
Set wendu = HMIRuntime.Tags("wendu")
HMIRuntime.Trace"Value:" &wendu.Read(1)&vbCrLf

Dim fuya
Set fuya = HMIRuntime.Tags("fuya")
HMIRuntime.Trace"Value:" &fuya.Read(1)&vbCrLf

Dim liuliang
Set liuliang = HMIRuntime.Tags("liuliang")
HMIRuntime.Trace"Value:" &liuliang.Read(1)&vbCrLf


Dim shijian_hour
Set shijian_hour = HMIRuntime.Tags("shijian_hour")
HMIRuntime.Trace"Value:" &shijian_hour.Read(1)&vbCrLf

Dim shijian_day
Set shijian_day = HMIRuntime.Tags("shijian_day")
HMIRuntime.Trace"Value:" &shijian_day.Read(1)&vbCrLf


Dim sysYear
Set sysYear = HMIRuntime.Tags("sysYear")
HMIRuntime.Trace"Value:" &sysYear.Read(1)&vbCrLf

Dim sysMonth
Set sysMonth = HMIRuntime.Tags("sysMonth")
HMIRuntime.Trace"Value:" &sysMonth.Read(1)&vbCrLf

Dim sysDay
Set sysDay = HMIRuntime.Tags("sysDay")
HMIRuntime.Trace"Value:" &sysDay.Read(1)&vbCrLf

Dim sysHour
Set sysHour = HMIRuntime.Tags("sysHour")
HMIRuntime.Trace"Value:" &sysHour.Read(1)&vbCrLf


Dim YY0,MM0,DD0,HH0

If sysHour.Value > 0 Then
 DD0=sysDay.Value
 MM0=sysMonth.Value
 YY0=sysYear.Value
 HH0=sysHour.Value+6
Else
 HH0=30
 If sysDay.Value > 1 Then
   DD0=sysDay.Value-1
   MM0=sysMonth.Value
   YY0=sysYear.Value 
 Else
   If sysMonth.Value > 1 Then
  
     If sysMonth.Value=2 Or sysMonth.Value=4 Or sysMonth.Value=6 Or sysMonth.Value=8 Or sysMonth.Value=9 Or sysMonth.Value=11 Then
       DD0=31
     Else
       If sysMonth.Value=5 Or sysMonth.Value=7 Or sysMonth.Value=10 Or sysMonth.Value=12 Then
        DD0=30
       Else
         If sysYear.Value Mod 4 =0 Then
           DD0=29
         Else
           DD0=28
         End If
        
       End If
     End If
        
    MM0=sysMonth.Value - 1
    YY0=sysYear.Value 
  Else 
      DD0=31
      MM0=12
      YY0=sysYear.Value-1
  End If
  
 End If
End If

Dim fso, f, fc, nf,fso1
Dim path,folderName
  path="F:\报表\"
  folderName=CStr(YY0)+"年"+CStr(MM0)+"月抽放报表"
 
    Set fso = CreateObject("scripting.FileSystemObject")
    Set f = fso.GetFolder(path)
    Set fso1= CreateObject("scripting.FileSystemObject")
    Set fc=f.SubFolders
   
    If Not (fso1.FolderExists(path&folderName)) Then

    Set nf = fc.Add(folderName)

   End If

 Dim name1
 name1=path+folderName+"\"+CStr(YY0)+"-"+CStr(MM0)+"-"+CStr(DD0)+"日报表1.xls"


Dim ob
 Set ob=CreateObject("Excel.Application")
 ob.WorkBooks.Open"F:\抽放报表模板文件\shiyanbaobiao.xls"

If sysHour.Value=1 Then
 ob.Sheets("Sheet1").Select
 ob.Range("B4:F27").Select
 ob.Selection.ClearContents
 ob.Range("A2").Select
 End If



ob.DisplayAlerts = False
ob.Cells(2,6).Value=CStr(YY0)+"年"+CStr(MM0)+"月"+CStr(DD0)+"日"

ob.Cells(HH0,2).VaLue=ch4_1.Value
ob.Cells(HH0,3).VaLue=ch4_2.Value
ob.Cells(HH0,4).VaLue=wendu.Value
ob.Cells(HH0,5).VaLue=fuya.Value
ob.Cells(HH0,6).VaLue=liuliang.Value
 ob.ActiveWorkbook.Save
 ob.ActiveWorkbook.SaveAs name1

ob.workbooks.Close
 ob.Quit
 Set ob=Nothing
If bit1.Value Then
  bit1.Write 0   
Else
  bit1.Write 1       
End If



henabj

  • 精华:0帖
  • 求助:0帖
  • 帖子:0帖 | 7回
  • 年度积分:0
  • 历史总积分:91
  • 注册:2013年1月05日
发表于:2013-01-20 15:56:29
1楼
。。。。。看着都费劲,你把程序分段执行下,变量都连到IO域,自己监视下是哪里执行不下去的

热门招聘
相关主题

官方公众号

智造工程师