我试过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
问题解决了,告诉我怎么用excel会文件打印报表吧!(本人也正缺这个)^_^
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
然后再做
第二种方法,如你所言,但我没有试过,我同事的程序采用你的方法,也说可行。