How do I access a sub in a New Class
On May 3, 6:09*am, "Mike" wrote:
Thanks Peter. It took me a while to understand what you were getting at. But
after everything fell into place, it gave me exactly what I was looking for.
*Thanks again!!!
"Peter T" <peter_t@discussions wrote in message
...
Difficult to follow your code because nothing like that's going to work..
First ensure Instancing for Class1 is PublicNotCreatable
In a normal module in the same project
Function NewClass1() As Class1
* *Set NewClass1 = New Class1
End Function
Ensure the project has a unique name, rename VBProject to say ClassTest
Save the file (might be an idea to close and reopen it)
In another wb set a reference to ClassTest, and in a normal module
something like the following
Sub test()
Dim c As ClassTest.Class1
Set c = ClassTest.NewClass1
MsgBox TypeName(c)
' type c and a dot and should get the intellisense
End Sub
Regards,
Peter T
"Mike" wrote in message
news:FfKdnc8MVZCHBkDWnZ2dnUVZ_j6dnZ2d@pghconnect. com...
From project "VBAProject(Book1.xlsm):"I am trying to access *sub
"subInNewClass" in a new class that is in Project "newclass(class
test.xlsm)". Both methods below produce errors.
Any help would be appreciated.
-----------------------------------
In Project newclass(class test.xlsm)
In Class Module Class1:
* * * * Option Explicit
* * * * Public Sub subInNewClass()
* * * * * * *MsgBox "I'm in"
* * * * End Sub
In VBAProject(Book1.xlsm):
Set reference to Project newclass
In Userform1
* * * * Option Explicit
* * * * Dim qq As New Class1
* * * * Private Sub UserForm_Click()
* * * * * * * qq.subInNewClass
* * * * End Sub
-----------------------------------------------------------
I also tried:
* * * * Option Explicit
* * * * Dim qq As Class1
* * * * Dim kk
* * * * Private Sub UserForm_Click()
* * * * * * * * *Set kk = qq
* * * * * * * * *kk.subInNewClass
* * * * End Sub- Hide quoted text -
- Show quoted text -
Sorry Peter n Mike
I couldn't get the thing correctly
What i expected was that to call the sub from the class module and use
in the module (by calling from the
module)
If i am not worng, there is no reference in the peters post about
class module.
How sub from a class be called from the normal module.
Let me make it more clear.
in a class module
msgbox "This is in a class module"
''''''
''''''''
in a normal module
sub callfromclass()
'''''' code goes here
end sub
And the output should be that there should be a message box.
|