1,445
社区成员




Private Sub Command1_Click()
'引用了excel 11.0
'--定义:注意关键字new创建excel新实例
' :去掉CreateObject.......语句,
' :引用了excel 11.0就不要再用这
' :个语句建立实例。
Dim excelApp As New Excel.Application
Dim excelBook As New Excel.Workbook
Dim excelSheet As New Excel.Worksheet
Dim excelPath As String '给出文件路径
excelPath = "c:\123.xls"
' --打开Excel对象
Set excelBook = excelApp.Workbooks.Open(excelPath)
Set excelSheet = excelBook.Worksheets(1)
'excelApp.Visible = True '愿意显示可以在这里显示
'--对excel的操作等
If excelSheet.Cells(excelSheet.Cells.SpecialCells(11).Row, 1) = "汇总:" Then
Else
excelSheet.Cells(excelSheet.Cells.SpecialCells(11).Row + 1, 1) = "汇总:"
End If
excelSheet.Range("C" & excelSheet.Cells.SpecialCells(11).Row).Activate
excelApp.ActiveCell.FormulaR1C1 = "=SUM(R[" & 5 - excelSheet.Cells.SpecialCells(11).Row & "]C:R[-1]C)"
' --对excel的关闭等操作
excelBook.Save
excelApp.Quit '这里一定要退出excel,否则内存中会有很的excel实例,运行一次增加一个。
Set excelApp = Nothing
Set excelBook = Nothing
Set excelSheet = Nothing
End Sub