Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Use of Function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
H.A. de Wilde - 20 Jan 2006 17:23 GMT
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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.