打开 Excel 文件以使用 VBA 读取而不显示 [英] Open Excel file for reading with VBA without display

查看:48
本文介绍了打开 Excel 文件以使用 VBA 读取而不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用宏搜索现有的 Excel 文件,但我不想在代码打开这些文件时显示这些文件.有没有办法让它们在后台"打开,可以这么说?

I want to search through existing Excel files with a macro, but I don't want to display those files when they're opened by the code. Is there a way to have them open "in the background", so to speak?

推荐答案

不确定是否可以在当前excel实例中隐形打开

Not sure if you can open them invisibly in the current excel instance

不过,您可以打开一个新的 excel 实例,将其隐藏,然后再打开工作簿

You can open a new instance of excel though, hide it and then open the workbooks

Dim app as New Excel.Application
app.Visible = False 'Visible is False by default, so this isn't necessary
Dim book As Excel.Workbook
Set book = app.Workbooks.Add(fileName)
'
' Do what you have to do
'
book.Close SaveChanges:=False
app.Quit
Set app = Nothing

正如其他人发布的那样,请确保在完成任何打开的工作簿后进行清理

As others have posted, make sure you clean up after you are finished with any opened workbooks

这篇关于打开 Excel 文件以使用 VBA 读取而不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆