请问怎样才能调用EXCEL的打印预览和打印设置?
我已经把记录集中的数据存到EXCEL文件中,但不知道怎么样进行打印设置,用exl.ActiveWorkbook.PrintView 好像也不行,程序会当在那里!
请各位帮忙!

解决方案 »

  1.   

    '---------打印表格----------------
        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
      

  2.   

    我现在需要的是对生成的EXCEL文件进行打印设置,比如纸张的方向,大小,最好能预览。
    to: xuewuya(血乌鸦) ,Exl.Sheets.PrintPreview 不行啊,程序会当掉的,EXCEL进程却一直在,下次在进行时又会开一个EXCEL进程。
      

  3.   

    我这里没有出现程序当掉的现象,最好能把代码都贴出来要set exl=nothing这样就会把进程退出了
      

  4.   

    With ActiveSheet.PageSetup
     .Orientation = xlPortrait '纵向  xlLandscape 横向
     
     .PaperSize = xlPaperA3 '纸张大小
           
     End With
      

  5.   

    to: xuewuya(血乌鸦)
    谢谢你的帮助!但我还想能有PRINTVIEW,不知道该怎么实现!
      

  6.   

    请问楼主,你实现了printpreview吗,能否共享一下你相关的代码