请教一个问题,找遍了baidu,但是没有答案
我写了一个VB程序,批量处理excel文件,由于有很多重复语句,需要劈分成几个sub子程序,如下代码中标注之间这段,试了几遍都不行,问题1:不知道这种with怎么传递到子过程中,
问题2:在子函数中需要把Set xlapp = CreateObject("Excel.Application")再写一遍么,子函数中“d1 = .Cells(k, 46) + d1”总是提示错误,
求大神帮忙指点一下,谢谢!
Private Sub Command15_Click()
pb1 = "D:\55.xls"
Set xlapp = CreateObject("Excel.Application")
xlapp.Visible = True
Set xlBook = xlapp.Workbooks.Open(pb1)
Set xlSheet = xlBook.Worksheets(1)
With xlSheet
a1 = ylSheet.Cells(2, 4)
For k = 5 To m ',
If InStr(.Cells(k, 7), "算前") <> 0 And InStr(.Cells(k, 8), "已开") <> 0 And IsNumeric(.Cells(k, 46)) And .Cells(k, 46) > 0 Then
'以下这段想写进sub子程序
d1 = .Cells(k, 46) + d1
por = .Cells(k, 47) + por
So = .Cells(k, 48) + So
WF = .Cells(k, 16) + WF
WD = .Cells(k, 17) + WD
YF = .Cells(k, 18) + YF
RRWF = .Cells(k, 21) + RRWF
RRWD = .Cells(k, 22) + RRWD
RRYF = .Cells(k, 23) + RRYF
JJWF = .Cells(k, 24) + JJWF
JJWD = .Cells(k, 25) + JJWD
JJYF = .Cells(k, 26) + JJYF
LCWF = .Cells(k, 30) + LCWF
LCWD = .Cells(k, 31) + LCWD
LCYF = .Cells(k, 32) + LCYF
.Cells(m1, 9) = a1
If a1 <> 0 Then .Cells(m1, 10) = d1 / a1
If d1 <> 0 Then .Cells(m1, 11) = por / d1
If por <> 0 Then .Cells(m1, 12) = So / por
If So <> 0 And YF <> 0 Then .Cells(m1, 13) = 1 / (WF * 100 / So)
If WF <> 0 Then .Cells(m1, 14) = WD / WF
If WF <> 0 Then .Cells(m1, 15) = YF * 10000 / WF
a1 = 0
d1 = 0
por = 0
'以上这段想写进sub子程序
End If ',5
Next ',4
下面代码无关省略