数据导出自动保存问题(关于vb与excel)

lindqp 2003-02-14 10:19:48
首先定义
Set xlApp = CreateObject("Excel.Application")
Set xlBook = Nothing
Set xlSheet = Nothing
Set xlBook = xlApp.Workbooks().Add
Set xlSheet = xlBook.Worksheets("sheet1")
数据导出后使用
xlApp.Application.Visible = false
不显示excel窗口,但是系统已经自动打开excel进程,如果使用xlBook.SaveAs c:\filename.xls 如此文件已经存在不能自动覆盖原文件。还有导出后的excel进程怎么自动关闭
使用
Set xlApp = Nothing '"交还控制给Excel
Set xlBook = Nothing
Set xlSheet = Nothing
后发现excel进程任然存在。
注:如将xlApp.Application.Visible = true,显示出导出数据并打开excel窗口,无此问题。
问:怎么自动保存导出文件并关闭excel进程!
...全文
114 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
FreshAir 2003-02-18
  • 打赏
  • 举报
回复
1.自动关闭EXCEL进程:
xlApp.Application.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing

2.覆盖已存在文件:
strFile = "c:\filename.xls"
If Dir(strFile) <> "" Then
Kill strFile
End If
xlBook.SaveAs strFile
ww_wyc 2003-02-17
  • 打赏
  • 举报
回复
装个Excel的帮助看看不就明白了吗
faib920 2003-02-17
  • 打赏
  • 举报
回复
xlApp.Quit
Set xlApp =Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
chenyu5188 2003-02-17
  • 打赏
  • 举报
回复
UP
battlet 2003-02-17
  • 打赏
  • 举报
回复
up
.........
battlet 2003-02-16
  • 打赏
  • 举报
回复
我也有同样的问题,谁能在一个星期内解决我再给200分!~
各位高手快出手吧,谢谢啦~
lindqp 2003-02-14
  • 打赏
  • 举报
回复
定义的内容copy错误
应该是:
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlQuery As Excel.QueryTable

2,503

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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