Execute class method on all worksheets?
Nik,
I'm not sure if this is what you want. You probably need to set up a
collection to hold the instances of your class -- this needs to be set up in
a module -- not a class module. See the following:
***I set up the following Class (named Class1)
--------------------------------------------------------
Dim mTheSheet As Worksheet
Sub test()
TheSheet.Cells(1, 1) = TheSheet.Name
End Sub
Property Let TheSheet(ByVal Value As Worksheet)
Set mTheSheet = Value
End Property
Property Get TheSheet() As Worksheet
Set TheSheet = mTheSheet
End Property
--------------------------------------------------------
***I have 3 worksheets, and in each of them I have the following:
--------------------------------------------------------
Private Sub Worksheet_Activate()
Dim x As New Class1
x.TheSheet = Me
cc.Add x
End Sub
--------------------------------------------------------
***Then in a regular module I have the following:
--------------------------------------------------------
Public cc As New Collection
Sub Main()
For Each WS In Worksheets
WS.Activate
Next WS
RunMethods
End Sub
Sub RunMethods()
Dim x As Class1
For Each x In cc
x.test
Next
End Sub
--------------------------------------------------------
***
Running Main accomplishes the goals of executing the method in each of the
classes instantiated by activated each of the worksheets.
I hope this is of help.
"Nik" wrote:
Hi,
I have an class instance on all my worksheets, is there some way I
can dynamically execute a method on these objects? Something like
for each worksheet in worksheets
worksheet.myObject.myMethod
next worksheet
?
|