I have 3 different modules and all of them have Subs that use at some stage the workbook the code is stored in. Module3 is where my ranges are being set and I have also put the public workbook variable there. For clarification: the two main subs complete different tasks and have nothing to do with each other - except that both use some of the same range and row variables, that's why I put them in an extra module.
I also have a userform that uses ThisWorkbook in its Initialize event. So far I've been using a public variable to declare the workbook (wbTest) in Module3, but I've been reading up on properties, which I have never used before. I was thinking about passing the wbTest from Module2 to the Userform, which I found out isn't possible for Initialize and that's how I came upon properties.
My question is: From examples I can see that it's fairly convenient to use properties when there is some kind of error handling or calculation associated with it. But in my case it is simply a Set wbTest command, nothing more - does choosing a property over a public variable still make sense in this case?
Module1:
Option Explicit
Private Sub MainSub1()
Call Module3.DefiningRanges
MsgBox wbTest.Range("A1").Value
End Sub
Module2:
Option Explicit
Private Sub MainSub2()
Call Module3.DefiningRanges
MsgBox wbTest.Range("A2").Value
frmSelection.Show
End Sub
Module3:
Option Explicit
Public wbTest As Workbook
Public Sub DefiningRanges()
Set wbTest = ThisWorkbook
End Sub
Userform frmSelection:
Option Explicit
Private Sub UserForm_Initialize()
MsgBox wbTest.Sheets(1).Range("B1").Value
End Sub
So this is a fairly general question, but on google I haven't found a simple case like my one. I now do know that public variables are frowned upon and many try to avoid them if possible - that's why I'm asking if I should replace it with a property here.
Public Property Get, right? I don't need to change the workbook once it's set, soProperty Setisn't necessary? - Alex