我有这个子例程来打开/关闭Application
的一些属性。声明为应用程序类型变量的子参数
Public Sub OPTIMIZE_VBA(ByVal isOn As Boolean)
Dim bHolder As Boolean
bHolder = Not isOn
On Error Resume Next
With Application
.DisplayAlerts = bHolder
.ScreenUpdating = bHolder
.EnableEvents = bHolder
.Calculation = IIf(isOn, xlCalculationManual, xlCalculationAutomatic)
.Calculate
If .VERSION > 12 Then .PrintCommunication = bHolder
End With
On Error GoTo 0
End Sub
说是有应用程序的不同实例,我想开启/关闭相同的属性,我将如何能够修改此代码,以接受参数/参数为不同的应用程序? 我期待着像;
Public Sub OPTIMIZE_VBA(ByVal isOn As Boolean, Optional ByVal ExApp As Excel.Application = thisApplication)
' rest of the code
End Sub
有了这个,我可以这样称呼它;
Sub Create_New_Excel_and_Disable_Properties()
'<~ Declare and prepare the new application
Dim NewExcel As Excel.Application
Set NewExcel = New Excel.Application
'<~ declare and set the workbook variable
Dim ExcelWbk As Excel.Workbook
Set ExcelWbk = NewExcel.Workbooks.Open("folder\template.xlsx")
'<~ call the sub that disables the Application.properties
OPTIMIZE_VBA False, NewExcel
End Sub
我猜你必须使用'set' – FunThomas
对不起 - 今天早上一直在用C#玩...... –
我可以假设我将无法将exapp设置为应用程序吗? –