I am trying to set the default value of an optional parameter to Excel's Application.ActiveWorkbook
property. Here is my failed attempt:
Function SheetExists(ByVal sheetName As String, _
Optional ByVal targetBook As Workbook = Application.ActiveWorkbook) As Boolean
This code caused a
Constant expression required : compile error
ActiveWorkbook
property (and other properties) as default values of parameters in functions and subroutines?Can you use something like this:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With