L.S.,
I have an Excel Workbook with a VBA Project containing 2 User Forms
with each a Command Button.
User Form 1:
'*************************
Option Explicit
Private Sub CmdUserForm1_Click()
ShowMessage
End Sub
Function ShowMessage()
MsgBox "test"
End Function
'*************************
Clicking on Command Button CmdUserForm1 results correctly in a Message
Box
showing the text "test" using the Funcion ShowMessage.
I like to use the Function ShowMessage also with User Form 2.
User Form 2:
'*************************
Option Explicit
Private Sub CmdUserForm2_Click()
ShowMessage
End Sub
'*************************
Unfortunately clicking on Command Button CmdUserForm2 results in an
Error Message: "Sub or Function not defined"
Of course I can add the Function also to User Form 2:
'*************************
Option Explicit
Private Sub CmdUserForm2_Click()
ShowMessage
End Sub
Function ShowMessage()
MsgBox "test"
End Function
'*************************
but does there exist a method to use the above mentioned Function with
both User Forms without adding the Function to both User Forms?

Signature
H.A. de Wilde
Zack Barresse - 20 Jan 2006 17:47 GMT
Hello,
Put your function in a Standard Module, declare it publically, and change it
to a Sub rather than a Function. I.e.
Public Sub ShowMessage()
Msgbox "test"
End sub
HTH

Signature
Regards,
Zack Barresse, aka firefytr, (GT = TFS FF Zack)
To email, remove the NO SPAM. Please keep correspondence to the board, as
to benefit others.
> L.S.,
>
[quoted text clipped - 48 lines]
> but does there exist a method to use the above mentioned Function with
> both User Forms without adding the Function to both User Forms?
Toppers - 20 Jan 2006 17:51 GMT
Hi,
Put the function in a general module not a Userform module
> L.S.,
>
[quoted text clipped - 48 lines]
> but does there exist a method to use the above mentioned Function with
> both User Forms without adding the Function to both User Forms?
H.A. de Wilde - 20 Jan 2006 18:07 GMT
Dear Zack and Toppers,
thank you both for yor help.
It works good now.
Kind Regards,
Hugo

Signature
H.A. de Wilde