PC Review


Reply
Thread Tools Rate Thread

Calling a subroutine with a command button

 
 
JonV
Guest
Posts: n/a
 
      7th Jul 2008
Hello,
I want to run a subroutine, when a command button is clicked. The
subroutine is stored in Sheet1 under the Microsoft Excel Objects folder of my
project and the command button is stored under UserForm1 in the Forms folder
of my project. Is there a certain command needed to reference the other
folder?

This is the code I have right now (Guessing_game is the name of the
subroutine I want to cal).

Private Sub CommandButton1_Click()
Sheet1.Activate
Call Guessing_game
End Sub

When I run this, I get an error stating "Sub or Function not defined."

Does anyone know how I can do this?
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      7th Jul 2008
First, unless that Guessing_Game routine is related to only the code in that
worksheet's module, I'd move it to a general module and just call it normally.

But you can do:

Option Explicit
Private Sub CommandButton1_Click()
Call Sheet1.Guessing_Game
End Sub

Sheet1 is the codename for the sheet, right???


JonV wrote:
>
> Hello,
> I want to run a subroutine, when a command button is clicked. The
> subroutine is stored in Sheet1 under the Microsoft Excel Objects folder of my
> project and the command button is stored under UserForm1 in the Forms folder
> of my project. Is there a certain command needed to reference the other
> folder?
>
> This is the code I have right now (Guessing_game is the name of the
> subroutine I want to cal).
>
> Private Sub CommandButton1_Click()
> Sheet1.Activate
> Call Guessing_game
> End Sub
>
> When I run this, I get an error stating "Sub or Function not defined."
>
> Does anyone know how I can do this?


--

Dave Peterson
 
Reply With Quote
 
JonV
Guest
Posts: n/a
 
      7th Jul 2008
I used your code and it worked. Thank-you very much.

"Dave Peterson" wrote:

> First, unless that Guessing_Game routine is related to only the code in that
> worksheet's module, I'd move it to a general module and just call it normally.
>
> But you can do:
>
> Option Explicit
> Private Sub CommandButton1_Click()
> Call Sheet1.Guessing_Game
> End Sub
>
> Sheet1 is the codename for the sheet, right???
>
>
> JonV wrote:
> >
> > Hello,
> > I want to run a subroutine, when a command button is clicked. The
> > subroutine is stored in Sheet1 under the Microsoft Excel Objects folder of my
> > project and the command button is stored under UserForm1 in the Forms folder
> > of my project. Is there a certain command needed to reference the other
> > folder?
> >
> > This is the code I have right now (Guessing_game is the name of the
> > subroutine I want to cal).
> >
> > Private Sub CommandButton1_Click()
> > Sheet1.Activate
> > Call Guessing_game
> > End Sub
> >
> > When I run this, I get an error stating "Sub or Function not defined."
> >
> > Does anyone know how I can do this?

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Activate a moacro subroutine from a userform command button Roger on Excel Microsoft Excel Programming 1 27th Nov 2009 09:17 PM
Calling an external file from a command button Joanne Microsoft Access VBA Modules 2 4th Jun 2009 12:28 AM
Calling up a specific report with a command button =?Utf-8?B?RnJhbmNpcyBDdW5uaW5naGFtLCBKci4=?= Microsoft Access Reports 1 15th Nov 2007 03:34 PM
Calling command button from another sheet Ian Microsoft Excel Programming 4 13th Apr 2006 07:41 PM
Calling a command button perico Microsoft Access Form Coding 2 30th Sep 2003 10:08 AM


Features
 

Advertising
 

Newsgroups
 


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