怎么打开某个excel文件,并修改内容啊.

2024-12-27 12:34:26
推荐回答(2个)
回答1:

按你的要求E2内容修改为1020

'先点击 工程-引用Microsoft Excel...
Private Sub Command1_Click()
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Set xlapp = CreateObject("excel.application")
Set xlbook = xlapp.Workbooks.Open("c:\1.xls")
Set xlsheet = xlbook.Worksheets("sheet1")
xlsheet.Cells(2, 5) = "1020"
xlbook.Save
xlbook.Close
Set xlapp = Nothing
MsgBox ("完成")
End Sub

回答2:

Dim ExcelSheet As Object
Set ExcelSheet = CreateObject("Excel.Sheet")

'设置 Application 对象使 Excel 可见
ExcelSheet.Application.Visible = True
'在表格的第一个单元中写些文本

Dim xlApp As Excel.Application

Dim xlBook As Excel.Workbook

Dim xlSheet As Excel.WorkSheet

Set xlApp = CreateObject("Excel.Application")

Set xlBook = xlApp.Workbooks.open("c:\1.xls")

Set xlSheet = xlBook.Worksheets(1)
ExcelSheet.Cells(1, 1).Value = "This is column A, row 1"
'将该表格保存到 C:\test.doc 目录
ExcelSheet.SaveAs "C:\ TEST.DOC"
'使用应用程序对象的 Quit 方法关闭 Excel。
ExcelSheet.Application.Quit
'释放该对象变量