CreateObject(“Excel.Application”)之间的区别.Workbooks.Open和只是Workbooks.Open [英] Difference between CreateObject("Excel.Application") .Workbooks.Open and just Workbooks.Open

查看:833
本文介绍了CreateObject(“Excel.Application”)之间的区别.Workbooks.Open和只是Workbooks.Open的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Workbooks.Open 来处理目录中包含的大量文件。但打开和关闭这些文件会使文件出现在任务栏中,我想避免不断闪烁。

I am currently using Workbooks.Open to process a large number of files contained in a directory. But opening and closing these files make the files appear in the task bar and I wanted to avoid the constant flickering.

我有一个建议,我可以使用 CreateObject 创建一个新的实例,因为它打开一个新的Excel实例这是隐藏的。

I got a suggestion from that I can use CreateObject to create a new instance since that opens a new Excel instance which is hidden.


  1. 在性能方面打开新工作簿的两种方式有什么不同吗?

  1. Is there any other difference between the two ways of opening new workbooks in terms of performance?

此外,我应该使用一个使用 CreateObject 创建的Excel实例打开所有的工作簿或做我需要为每个需要处理的工作簿创建一个实例(,这似乎浪费了大量的内存和更少的速度)。

Also, should I just use one instance of Excel created using CreateObject to open all Workbooks or do I need to create one instance for each workbook I have to process (which seems like a waste of lot of memory and less speed)?


推荐答案

Workbooks.Open 使用当前的MS Excel实例和 CreateObject(Excel.Application)创建一个新的MS Excel实例。您可以阅读 CreateObject 这里

Workbooks.Open uses the current MS Excel instance and CreateObject("Excel.Application") creates a new MS Excel instance. You can read up on CreateObject here.

只需发出一个 Workbooks.Open 创建新实例之后,不会确保工作簿在新实例中打开。你必须绑定它。例如

Simply issuing a Workbooks.Open after creating a new instance will not ensure that the workbooks open in the new instance. You will have to bind with it. For example

Dim oXLApp As Object, wb As Object

Set oXLApp = CreateObject("Excel.Application")

'~~> Hide Excel
oXLApp.Visible = False

'~~> Open files
Set wb = oXLApp.Workbooks.Open("C:\Sample.xls")

关于您的其他问题


此外,我应该使用一个使用CreateObject创建的Excel实例来打开所有的工作簿需要为每个需要处理的工作簿创建一个实例

Also, should I just use one instance of Excel created using CreateObject to open all Workbooks or do I need to create one instance for each workbook I have to process

您不需要多个实例。您可以使用一个实例。例如

You don't need several instances. You can work with one instance. For example

Dim oXLApp As Object, wb As Object

Set oXLApp = CreateObject("Excel.Application")

'~~> Hide Excel
oXLApp.Visible = False

'~~> Open files
Set wb = oXLApp.Workbooks.Open("C:\Sample1.xls")

'
'~~> Do some Stuff
'

wb.Close (False)

'~~> Open files
Set wb = oXLApp.Workbooks.Open("C:\Sample2.xls")
'
'~~> Do some Stuff
'

wb.Close (False)

'
'~~> And So on
'

这篇关于CreateObject(“Excel.Application”)之间的区别.Workbooks.Open和只是Workbooks.Open的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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