你没有正常的释放对象Dim exl As New Excel.Application Dim book As Excel.Workbook Dim sheet As Excel.Worksheet '先使用excel制作一个模板 Set book = exl.Workbooks.Open("c:\temp1.xls") Set sheet = book.Worksheets(1) book.Application.DisplayAlerts = False '在excel的格子中写入你想打印的内容 With sheet
Dim book As Excel.Workbook
Dim sheet As Excel.Worksheet
'先使用excel制作一个模板
Set book = exl.Workbooks.Open("c:\temp1.xls")
Set sheet = book.Worksheets(1)
book.Application.DisplayAlerts = False
'在excel的格子中写入你想打印的内容
With sheet
'.Cells(Row, col) = ""
'这里使用
Range("C4").Select
ActiveSheet.Pictures.Insert( _
"C:\Documents and Settings\Administrator\My Documents\My Pictures\样品.jpg"). _
Select
'Selection.AutoFill Destination:=Range("A18:J18"), Type:=xlFillDefault
.Columns("A:A").ColumnWidth = 30
' Range("A17").Select
' ActiveCell.FormulaR1C1 = "=SUM(R[-16]C:R[-1]C)"
' Range("A18").Select
' Selection.AutoFill Destination:=Range("A18:J18"), Type:=xlFillDefault
' Range("A18:J18").Select
' Range("A17").Select
' Selection.AutoFill Destination:=Range("A17:J17"), Type:=xlFillDefault
' Range("A17:J17").Select
' Range("E16").Select
'这里使用
End With
'sheet.PrintOut'从这里开始保存并且释放对象'你应该就是缺少这个东西book.Save
book.Close
Set book = Nothing
exl.Quit
Set exl = Nothing
加入
exl.close
set exl=nothing
就可以了
按下界面右上的那个关闭按钮,或者Unload me都会触发Form_Unload
所以只要把结束exl的代码写到Form_Unload中就可以了