vb 调用excel的自动化程序为什么没推出不了excel

cyclamen 2000-06-16 09:31:00
我完成了一个VB的自动化程序主要目的是将文本的内容导入一个格式化好的Excel表中,我这样得到对象:
On Error GoTo APP_ERR02
Set xlApp = GetObject(, "Excel.Application")
Set xlBook = xlApp.Workbooks.Add(Text6.Text) '加入模板
Set xlsheets = xlBook.Worksheets
Set xlsheet = xlBook.Worksheets(1)
Set xlsheet2 = xlsheets(1)
xlsheets(1).Copy after:=xlsheets(1)
Set xlsheet = xlsheets(2)
xlsheet.Application.Visible = False
xlsheet.Application.DisplayAlerts = False

然后读入数据
Do


str2 = readstring(f) '从文本中读数据
'写入每一行
If str2 <> Chr(13) And str2 <> Chr(10) Then
Select Case j
Case 1
xlsheet.Cells(i, 2).Value = str2
j = j + 1
Case 2
xlsheet.Cells(i, 5).Value = str2
j = j + 1
Case 3
xlsheet.Cells(i, 8).Value = str2
j = j + 1
Case 4
xlsheet.Cells(i, 20).Value = str2
j = j + 1
Case 5
xlsheet.Cells(i, 21).Value = str2
j = j + 1
Case 6
xlsheet.Cells(i, 19).Value = str2
j = j + 1
Case 7
xlsheet.Cells(i, 11).Value = str2
j = j + 1
Case 8
xlsheet.Cells(i, 17).Value = str2
j = j + 1

End Select

End If


If str2 = Chr(10) Then
i = i + 1
j = 1
ProgressBar3.Value = ProgressBar3.Value + 1

If i > VScroll6.Value + 2 Then
i = 3
ProgressBar3.Value = 1
xlsheet.Name = "第" & k & "页"
xlsheets(1).Copy after:=xlsheets(k + 1)
Set xlsheet = xlsheets(k + 2)
k = k + 1
End If
End If
Loop While f.AtEndOfStream <> True

退出Excel
xlBook.SaveAs Text4.Text '保存
xlBook.Close
xlApp.Quit
Set xlApp = Nothing


问题是这样并没有退出Excel,因为任务管理器中还有Excel的进程,而只有我的整个程序退出才会使这个Excel进程退出,这就给我带来了一些麻烦,因为我的程序无法和Excel同时运行!
我实在是不知是为什么,不知该怎么办了!
请各位高手帮帮忙!

...全文
154 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Un1 2000-06-16
  • 打赏
  • 举报
回复
还需要释放xlsheets、xlBook等对象。

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧