我正在尝试将可选参数的默认值设置为 Excel 的 Application.ActiveWorkbook
属性。这是我失败的尝试:
尝试的代码
Function SheetExists(ByVal sheetName As String, _
Optional ByVal targetBook As Workbook = Application.ActiveWorkbook) As Boolean
结果
这段代码导致了
问题
ActiveWorkbook
属性(和其他属性)作为函数和子例程中参数的默认值? 最佳答案
你可以使用这样的东西:
Public function SheetExists(ByVal sheetName As String, Optional wb As Workbook)
If wb Is Nothing Then Set wb = Application.ActiveWorkbook 'or ThisWorkbook
'your code here, for example
wb.Application.Calculation = xlAutomatic
End Sub
关于vba - 如何将 ActiveSheet、ActiveWorkbook 或 ThisWorkbook 设置为 VBA 中可选参数的默认值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48407542/