为什么CASE 1 情况下不能正确打印啊
本帖最后由 bcrun 于 2013-05-19 16:02:46 编辑
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open("mb.xls")
On Error Resume Next
Select Case rs1.Fields("gsyh")
Case 0
Set xlSheet = xlBook.Worksheets("sheet1")
With xlSheet
.Cells(5, 20) = rs.Fields("cust")
.Cells(9, 12) = rs.Fields("numb")
.Cells(6, 3) = DX(rs.Fields("numb"))
.Cells(4, 3) = rs1.Fields("gsmc")
.Cells(5, 3) = rs1.Fields("gszh")
End With
xlSheet.PrintOut
Case 1
Set xlSheet = xlBook.Worksheets("sheet3")
With xlSheet
.Cells(5, 20) = rs.Fields("cust")
.Cells(9, 12) = rs.Fields("numb")
.Cells(6, 3) = DX(rs.Fields("numb"))
.Cells(4, 3) = rs1.Fields("gsmc")
.Cells(5, 3) = rs1.Fields("gszh")
End With
xlSheet.PrintOut
Case 2
Set xlSheet = xlBook.Worksheets("sheet2")
With xlSheet
.Cells(2, 4) = rs.Fields("cust")
.Cells(5, 6) = rs.Fields("numb")
.Cells(4, 6) = DX(rs.Fields("numb"))
.Cells(3, 8) = rs1.Fields("gsmc")
.Cells(3, 4) = rs1.Fields("gszh")
End With
xlSheet.PrintOut
Case Else
MsgBox ("SORRY没有打印模板")
End Select
Application.DisplayAlerts = False
xlBook.Close (False)
xlApp.quit
Set xlBook = Nothing
Set xlApp = Nothing
[解决办法]
逐行运行调试, 看看前面的语句是否出错