What does it take to get class functions to execute?

O

OfficeUser

I have an .ocx file named MyProject. It contains a class named MyClass which
contains two VBA functions:
Function MsgHello()
MsgBox "Hello World"
End Function

Function GoodByeWorld()
MsgBox "Good Bye World"
End Function

MyProject is referenced in Tools-References.

In the Sheet1 code module I have:
Public oMyClass As New MyProject.MyClass
on the Declarations section.

In the Sheet1 mudule I have this sub:
Private Sub Steve()
oMyClass.MsgHello
oMyClass.GoodByeWorld
End Sub

When I wrote the above code, when I typed oMyClass., intellisense popped up
a list containing MsgHelp and GoodByeWorld.

1. Should Sub Steve() be able to run in the Sheet1 module? If not, where
should I put the code?

2. When I try to run Sub Steve(), I get the errpr message "Invalid Use Of
New Keyword".

3. When I remove New from the line of code in the Declarations secyion, I
get the error message "Object Variable Or With Block Variable Not Set"

What does it take to get the functions, MsgHello and GoodByeWorld, to
execute?

Thanks!!!
 
D

Dave D-C

I don't get that error.
oMyClass.MsgHello
executes the function (Sub would be better?)

Would you like to email me the .ocx file?
And the .vbp and .cls and .ctl files if you have them?
dacromley @ wyoming . com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top