更改应用程序.在不同的Excel过程中进行计算



在VBA子程序中,我将值写入另一个";目标";在单独的Excel进程中运行的工作簿,如以下所示:

Set xlWB = GetObject(STR_TARGET_WORKBOOK_FILENAME)
xlWB.Worksheets(STR_TARGET_SHEET).Range("B1").value = Now()

当我向目标工作簿中写入值时,我想挂起它中的计算。如果它与此VBA在同一Excel进程中运行,我可以只执行Application.Calculation = xlCalculationManual

如何在运行目标工作簿的Excel进程中获取和设置Application.Calculation模式?

外部工作簿对象也将引用其应用程序,因此我们可以简单地执行:

Dim xlWB As Object
Dim calcMode As Integer
Set xlWB = GetObject(STR_TARGET_WORKBOOK_FILENAME)
' Get the Target's calculation mode
calcMode = xlWB.Application.Calculation
' Suspend calculation in the Target's Excel process
xlWB.Application.Calculation = xlCalculationManual
' ... do stuff to xlWB
' Restore whatever calculation mode was in that process
xlWB.Application.Calculation = calcMode

相关内容

  • 没有找到相关文章

最新更新