VB打印问题
各位大神请指点,小弟用EXCEL自制的表格做为打印模版.下面是打印代码,第一次加载窗口,可以正常打印.但是第二打印就打印不了.实在是想不出为什么!我是新手,请各位大神指点.万份感谢!
Private Sub PRI() '打印
On Error Resume Next
Text3.Text = 1
If Adodc2.Recordset.RecordCount = 0 Then Exit Sub
Dim R As String, i As Integer
Dim sSource, sDestination As String
Set mxlApp = New excel.Application
Set mxlApp = CreateObject("Excel.Application")
R = "W:\warehouse\PRI.xlsx"
Set mxlbook = mxlApp.Workbooks.Open(R)
Set mxlSheet = mxlbook.Worksheets(1)
mxlApp.Visible = False
mxlSheet.Cells(2, 2) = Adodc2.Recordset.Fields("LLDW") '领料单位
mxlSheet.Cells(2, 4) = Adodc2.Recordset.Fields("LLData") '日期
mxlSheet.Cells(2, 7) = Adodc2.Recordset.Fields("QXDH") '销售单号
mxlSheet.Cells(1, 7) = Adodc2.Recordset.Fields("LLDH") '领料单号
'mxlSheet.Cells(1, 2) = Adodc2.Recordset.Fields("LLDH") '款号
mxlSheet.Cells(13, 5) = Adodc2.Recordset.Fields("LLKDR") '开单人
Adodc2.Recordset.MoveFirst
For H = 4 To Adodc2.Recordset.RecordCount + 5
mxlSheet.Cells(H, 1) = Adodc2.Recordset.Fields("wlnumber") '物料编码
mxlSheet.Cells(H, 2) = Adodc2.Recordset.Fields("wlname") '规格名称
mxlSheet.Cells(H, 3) = Adodc2.Recordset.Fields("wlunit") '单位
mxlSheet.Cells(H, 4) = Adodc2.Recordset.Fields("LLSL") '领料数量'
mxlSheet.Cells(H, 5) = Adodc2.Recordset.Fields("wlprice") '单价
mxlSheet.Cells(H, 7) = Adodc2.Recordset.Fields("wlremarks") '备注
Adodc2.Recordset.MoveNext
Next H
Text3.Text = ""
ActiveWindow.SelectedSheets.PrintOut Copies:=1 '直接使用默认打印机打印
mxlApp.DisplayAlerts = False '设置关闭EXCEL时不提示是否保存'
mxlbook.Application.Quit '关闭EXCEL
End Sub