I'm not the most savvy VBA coder so I'd appreciate your advice! I have multiple modules where each of these modules need access to one workbook (Master.xlsm). Is it faster to 1) use a public variable to access this workbook in other modules or to 2) open it in each sub that uses it?
Option #1
I'd set the workbook to a public variable and have it assigned whenever the workbook is opened using Auto_Open.
Public wbk_MASTER As Workbook
Sub Auto_Open()
Set wbk_MASTER = Workbooks.Open("C:\Master.xlsm")
End Sub
Option #2
Alternatively, in each sub that uses Master.xlsm, I'd just pass it like:
Sub DoSomething(wbk_master as Workbook)
' do something
End Sub
That assumes that whatever sub calls this sub would look like:
Sub CallDoSomething()
Dim wbk_master as Workbook
Set wbk_master = Workbooks.Open("C:\Master.xlsm")
Call DoSomething(wbk_master)
End Sub
Note that there'd be multiple subs like DoSomething. If it makes a difference, I'd also like to have variables for important sheets in Master.xlsm and even values from specific ranges.
Personally, I think Option #1 is cleaner but which is faster?