B
Brett
I need some assistance from someone who is knows about Class Modules please.
I'm trying to set up some Class Mods so that I can refer to a
Workbook/Sheet/Range using a variety of the properties. So far I have the
following in a class module called CTLS:
Option Explicit
Private pTLS As Workbook
Private Sub Init()
Set pTLS = Workbooks("1. TOOLS.xls")
End Sub
Public Property Get TLS() As Workbook
Attribute TT.VB_UserMemId = 0 'THIS LINE IS NOT VISIBLE in VBE
If pTLS Is Nothing Then Init
Set TLS = pTLS
End Property
Public Property Get Sheets() As Excel.Sheets
Set Sheets = pTLS.Sheets
End Property
Public Property Get Name() As String
Name = pTLS.Name
End Property
Private Sub Class_Initialize()
Init
End Sub
Private Sub Class_Terminate()
Set pTLS = Nothing
End Sub
and in a normal module I have
Option Explicit
Public TLS As New CTLS
Public TT As New CTT
The next Class Module is CTT:
Option Explicit
Private pTT As Worksheet
Private Sub Init()
Set pTT = Workbooks("1. TOOLS.xls").Worksheets("TOOLS")
End Sub
Public Property Get TT() As Worksheet
If pTT Is Nothing Then Init
Set TT = pTT
End Property
Private Sub Class_Initialize()
Init
End Sub
Private Sub Class_Terminate()
Set pTT = Nothing
End Sub
So, with this I can type into the Immed Window
? TLS.Name
1. TOOLS.xls
? TLS.sheets("TOOLS").name
TOOLS
and get the correct results as shown there.
What I can't figure out (and I've read Chip's site and read Walkenbach's
chapters) is how to do some other things such as
TLS.save
TLS.activate
TT.activate (TT is a sheet)
TT.select
TT.visible = false etc etc
In particular I need to be able to refer to ANY range in TT, which I imagine
will need another Class Mod called (say) CTrng (C for class, T for TOOLS). I
need to be able to do any of the usual things that we do with ranges.
For the record, the Attribute statement was added via Notepad, and then the
class module imported from the notepad, so that auto-instancing is set up.
Therefore the values of TLS and TT are always refreshed when they are needed.
From this point I am completely stuck. Class Modules are not the easiest
things to wrap my head around, and any assistance will be greatly
appreciated. Regards, Brett.
I'm trying to set up some Class Mods so that I can refer to a
Workbook/Sheet/Range using a variety of the properties. So far I have the
following in a class module called CTLS:
Option Explicit
Private pTLS As Workbook
Private Sub Init()
Set pTLS = Workbooks("1. TOOLS.xls")
End Sub
Public Property Get TLS() As Workbook
Attribute TT.VB_UserMemId = 0 'THIS LINE IS NOT VISIBLE in VBE
If pTLS Is Nothing Then Init
Set TLS = pTLS
End Property
Public Property Get Sheets() As Excel.Sheets
Set Sheets = pTLS.Sheets
End Property
Public Property Get Name() As String
Name = pTLS.Name
End Property
Private Sub Class_Initialize()
Init
End Sub
Private Sub Class_Terminate()
Set pTLS = Nothing
End Sub
and in a normal module I have
Option Explicit
Public TLS As New CTLS
Public TT As New CTT
The next Class Module is CTT:
Option Explicit
Private pTT As Worksheet
Private Sub Init()
Set pTT = Workbooks("1. TOOLS.xls").Worksheets("TOOLS")
End Sub
Public Property Get TT() As Worksheet
If pTT Is Nothing Then Init
Set TT = pTT
End Property
Private Sub Class_Initialize()
Init
End Sub
Private Sub Class_Terminate()
Set pTT = Nothing
End Sub
So, with this I can type into the Immed Window
? TLS.Name
1. TOOLS.xls
? TLS.sheets("TOOLS").name
TOOLS
and get the correct results as shown there.
What I can't figure out (and I've read Chip's site and read Walkenbach's
chapters) is how to do some other things such as
TLS.save
TLS.activate
TT.activate (TT is a sheet)
TT.select
TT.visible = false etc etc
In particular I need to be able to refer to ANY range in TT, which I imagine
will need another Class Mod called (say) CTrng (C for class, T for TOOLS). I
need to be able to do any of the usual things that we do with ranges.
For the record, the Attribute statement was added via Notepad, and then the
class module imported from the notepad, so that auto-instancing is set up.
Therefore the values of TLS and TT are always refreshed when they are needed.
From this point I am completely stuck. Class Modules are not the easiest
things to wrap my head around, and any assistance will be greatly
appreciated. Regards, Brett.