ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   What does it take to get class functions to execute? (https://www.excelbanter.com/excel-programming/405851-what-does-take-get-class-functions-execute.html)

OfficeUser

What does it take to get class functions to execute?
 
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!!!



Dave D-C[_3_]

What does it take to get class functions to execute?
 
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

"OfficeUser" wrote:
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!!!




All times are GMT +1. The time now is 12:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com