'---------打印表格---------------- Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet1 As Excel.Worksheet Dim TempS As String Dim TempDestination As String
'生成临时文件 If Not CreateATempFile("G001", "001") Then Exit Function TempDestination = App.Path & "\temporay\001.xls"
'转入Excel Set xlApp = New Excel.Application Set xlApp = CreateObject("Excel.Application") xlApp.Visible = False Set xlBook = xlApp.Workbooks.Open(TempDestination) Set xlSheet1 = xlBook.Worksheets(1)
'填写表格内容 xlSheet1.Cells(3, 2) = Text1(0).Text xlSheet1.Cells(4, 2) = Text1(1).Text xlSheet1.Cells(5, 2) = Text1(2).Text xlSheet1.Cells(6, 2) = Text1(3).Text xlSheet1.Cells(7, 2) = Text1(4).Text xlSheet1.Cells(8, 2) = Text1(5).Text xlSheet1.Cells(9, 2) = Text1(7).Text xlSheet1.Cells(10, 2) = Text1(8).Text xlSheet1.Cells(11, 2) = Text1(6).Text xlSheet1.Cells(12, 2) = Text1(9).Text TempS = Trim(Text1(11).Text) If TempS <> "" Then If Trim(Text1(10).Text) <> "" Then TempS = Text1(10).Text & "(" & TempS & ")" End If Else If Trim(Text1(10).Text) <> "" Then TempS = Trim(Text1(10).Text) End If End If xlSheet1.Cells(13, 2) = TempS xlSheet1.Cells(14, 2) = Text1(12).Text xlSheet1.Cells(15, 2) = Text2.Text
'打印表格 On Error GoTo ErrHandle xlBook.Save xlSheet1.PrintOut xlApp.Quit Set xlSheet1 = Nothing Set xlBook = Nothing Set xlApp = Nothing Kill TempDestination
ErrHandle: MsgBox "打印出错,请重试(或调出\Temporay\001.xls直接打印)!", vbInformation, "给你提示" xlApp.Quit Set xlBook = Nothing Set xlSheet1 = Nothing Set xlApp = Nothing
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet1 As Excel.Worksheet
Dim TempS As String
Dim TempDestination As String
'生成临时文件
If Not CreateATempFile("G001", "001") Then Exit Function
TempDestination = App.Path & "\temporay\001.xls"
'转入Excel
Set xlApp = New Excel.Application
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open(TempDestination)
Set xlSheet1 = xlBook.Worksheets(1)
'填写表格内容
xlSheet1.Cells(3, 2) = Text1(0).Text
xlSheet1.Cells(4, 2) = Text1(1).Text
xlSheet1.Cells(5, 2) = Text1(2).Text
xlSheet1.Cells(6, 2) = Text1(3).Text
xlSheet1.Cells(7, 2) = Text1(4).Text
xlSheet1.Cells(8, 2) = Text1(5).Text
xlSheet1.Cells(9, 2) = Text1(7).Text
xlSheet1.Cells(10, 2) = Text1(8).Text
xlSheet1.Cells(11, 2) = Text1(6).Text
xlSheet1.Cells(12, 2) = Text1(9).Text
TempS = Trim(Text1(11).Text)
If TempS <> "" Then
If Trim(Text1(10).Text) <> "" Then
TempS = Text1(10).Text & "(" & TempS & ")"
End If
Else
If Trim(Text1(10).Text) <> "" Then
TempS = Trim(Text1(10).Text)
End If
End If
xlSheet1.Cells(13, 2) = TempS
xlSheet1.Cells(14, 2) = Text1(12).Text
xlSheet1.Cells(15, 2) = Text2.Text
'打印表格
On Error GoTo ErrHandle
xlBook.Save
xlSheet1.PrintOut
xlApp.Quit
Set xlSheet1 = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
Kill TempDestination
ErrHandle:
MsgBox "打印出错,请重试(或调出\Temporay\001.xls直接打印)!", vbInformation, "给你提示"
xlApp.Quit
Set xlBook = Nothing
Set xlSheet1 = Nothing
Set xlApp = Nothing
to: xuewuya(血乌鸦) ,Exl.Sheets.PrintPreview 不行啊,程序会当掉的,EXCEL进程却一直在,下次在进行时又会开一个EXCEL进程。
.Orientation = xlPortrait '纵向 xlLandscape 横向
.PaperSize = xlPaperA3 '纸张大小
End With
谢谢你的帮助!但我还想能有PRINTVIEW,不知道该怎么实现!