Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Calling a subroutine with a command button

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Calling a subroutine with a command button

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Calling a subroutine with a command button

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a VBA add in from a macro subroutine [email protected] Excel Programming 1 April 6th 07 10:09 PM
Calling command button from another sheet Ian[_17_] Excel Programming 4 April 13th 06 07:41 PM
HELP! Calling subroutine in different workbook ChrisWalker Excel Programming 3 March 1st 06 11:32 AM
Calling a subroutine in a loop Jeff@DE Excel Programming 1 January 9th 06 09:56 AM
Calling the Solver via a subroutine James[_8_] Excel Programming 1 July 10th 03 01:08 AM


All times are GMT +1. The time now is 02:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"