我有一个EXCEL文件,现在想在这个文件里的空格处添加内容,但是总报一些错误,包括要保存副本什么的,我的代码如下:
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(pathstr + "\rectifier.xls")
xlApp.Visible = False
Set xlsheet = xlBook.Worksheets(1)
xlsheet.Activate
If j = 0 Then
For i = 2 To 20
If xlApp.Cells(i, 1) = "" And xlApp.Cells(i, 2) = "" And xlApp.Cells(i, 3) = "" And xlApp.Cells(i, 4) = "" And xlApp.Cells(i, 5) = "" Then
xlApp.Cells(i, 1) = data.Text1.Text
xlApp.Cells(i, 2) = data.Text2.Text
xlApp.Cells(i, 3) = data.Text3.Text
xlApp.Cells(i, 4) = data.Text4.Text
xlApp.Cells(i, 5) = data.Text5.Text
j = 1
End If
Next i
End If
xlApp.ActiveWorkbook.save
xlBook.Close (True)
xlApp.Quit
Set xlApp = Nothing
求高人指点!
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(pathstr + "\rectifier.xls")
xlApp.Visible = False
Set xlsheet = xlBook.Worksheets(1)
xlsheet.Activate
If j = 0 Then
For i = 2 To 20
If xlApp.Cells(i, 1) = "" And xlApp.Cells(i, 2) = "" And xlApp.Cells(i, 3) = "" And xlApp.Cells(i, 4) = "" And xlApp.Cells(i, 5) = "" Then
xlApp.Cells(i, 1) = data.Text1.Text
xlApp.Cells(i, 2) = data.Text2.Text
xlApp.Cells(i, 3) = data.Text3.Text
xlApp.Cells(i, 4) = data.Text4.Text
xlApp.Cells(i, 5) = data.Text5.Text
j = 1
End If
Next i
End If
xlApp.ActiveWorkbook.save
xlBook.Close (True)
xlApp.Quit
Set xlApp = Nothing
求高人指点!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货