如何断开与excel文件的联系?

Accelerator 2005-09-22 08:22:38
代码生成了一个excel文件,当关闭Excel.Application对象时,Excel文件也会跟着关闭(出对话框问是否保存)。
1、想让Excel.Application对象与它生成的Excel文件断开联系,即关闭对象对产生的excel没有任何影响,不去自作主张的关闭excel文件。
2、关闭对象后,再次生成另一个excel文件的时候程序会报错,是否是因为没有完全释放掉这个对象?如何做?

谢谢!
...全文
237 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Accelerator 2005-09-23
  • 打赏
  • 举报
回复
对象应该释放了的,下面是我的代码:

Dim AppExcel As Excel.Application '定义
Dim BookExcel As Excel.Workbook '工作簿对象
Dim sheetexcel As Excel.Worksheet '工作表

Set AppExcel = New Excel.Application '创建excel对象
Set BookExcel = AppExcel.Workbooks.Add '添加工作簿
Set sheetexcel = BookExcel.Worksheets("sheet1") '添加工作表

......
AppExcel.Quit'这里退出的时候,Excel提示我是否保存新建的文件
Set sheetexcel = Nothing
Set BookExcel = Nothing
Set AppExcel = Nothing
Andy__Huang 2005-09-22
  • 打赏
  • 举报
回复
再個體一點就是:
...............
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("D:\SWEB\Excel\PrintPhoto.xls")
Set xlSheet = xlBook.Worksheets(2)
xlApp.Visible = False
xlSheet.Cells( 2, 2) = "adfasdfasdfasdf"
xlSheet.Cells(3, 6)=200
...............

....
Andy__Huang 2005-09-22
  • 打赏
  • 举报
回复

估計是你沒有譯放對象

Dim xlApp As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet
Dim strsql As String
Dim rsPict As New ADODB.Recordset

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("D:\SWEB\Excel\PrintPhoto.xls")
Set xlSheet = xlBook.Worksheets(2)
xlApp.Visible = False

xlSheet.Cells(1, 1).Select
xlApp.Visible = True

Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing

7,759

社区成员

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

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