声明Excel对象 Excel对象.ActiveSheet.PrintPreview

解决方案 »

  1.   

    关注!
    问题解决了,告诉我怎么用excel会文件打印报表吧!(本人也正缺这个)^_^
      

  2.   

    我试过PrintPreview方法,结果……死机,顺便问一下,我不知道要把mxlsheet定义成什么,现在我只能把它定义成OBJECT,否则无论是定义成Excel.Sheet还是Excel.Sheets都会报错
    Option ExplicitDim mxlApp As Excel.Application
    Dim mxlBook As Excel.Workbook
    Dim mxlSheet As ObjectPrivate Sub Form_Load()    Dim sSource, sDestination As String    Set mxlApp = New Excel.Application
        
        Set mxlApp = CreateObject("Excel.Application")
        
        sSource = App.Path & "\test.xls"
        sDestination = App.Path & "\temp.xls"
        FileCopy sSource, sDestination
        
        mxlApp.Visible = False
        Set mxlBook = mxlApp.Workbooks.Open(sDestination)
        Set mxlSheet = mxlBook.Worksheets(1)
        mxlSheet.Cells(5, 2) = "1"
        mxlSheet.Cells(5, 4) = "2"
        mxlSheet.Cells(5, 6) = "3"
        mxlSheet.Cells(7, 2) = "4"
        mxlSheet.Cells(7, 4) = "5"
        mxlSheet.Cells(7, 6) = "6"
        
        mxlBook.Application.DisplayAlerts = False
        mxlBook.Save
        mxlSheet.PrintPreview
        mxlBook.Application.Quit
    End Sub
      

  3.   

    可以新建个excel类,
    然后再做
      

  4.   

    有两办法,其一编写VBA程序,我的程序通过运行表明可行。
    第二种方法,如你所言,但我没有试过,我同事的程序采用你的方法,也说可行。