vb excel怎么追加写入

来源:百度知道 编辑:UC知道 时间:2024/05/22 01:33:03
Private Sub Form_Load()
Dim excel As Object

Dim sheet As Object

Dim workbook As Object

Set excel = CreateObject("excel.application")

Set workbook = excel.workbooks.open(App.Path & "\123.xls")

Set sheet = workbook.activesheet

'读取excel 单元格a1的内容

Dim a As Integer

a = sheet.range("a1").Value

a = sheet.cells(1, 2)

'设置单元格a2的内容

sheet.range("a2").Value = 3242332

'关闭

workbook.Close

excel.quit

Set sheet = Nothing

Set workbook = Nothing

Set excel = Nothing
End Sub
以上是简单的读写,但我想追加该怎么写呢

sheet.range("a2").Value = 3242332
这一句就是往EXCEL中添加内容,是指把3242332 输入到A2单元格内,您要追加的意思是指在其它单元格中添加数据吧,那就重复做这个操作即可.
第一次操作完成,保存后,再次打开也是用上面的代码,只是你要指定新的单元格进行赋值,原有单元格数据是不变的,除非你用命令改变.