Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Zak Zak is offline
external usenet poster
 
Posts: 144
Default Assigning macro to button

I have tried many times to add my macro to a button but it does not work. I
have tried both the control toolbox and the forms menu.

I am in design view when i create the button, double click it to show the
VBE, enter the below code, go back to the button coming out of design view
but nothing happens! not even an error. same when i do it via the forms menu,
i assign the button but nothing happens!!
(replace is my macros name.)

Private Sub CommandButton1_Click()
Run "replace"

End Sub

please help. thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Assigning macro to button



"Zak" wrote:

I have tried many times to add my macro to a button but it does not work. I
have tried both the control toolbox and the forms menu.

I am in design view when i create the button, double click it to show the
VBE, enter the below code, go back to the button coming out of design view
but nothing happens! not even an error. same when i do it via the forms menu,
i assign the button but nothing happens!!
(replace is my macros name.)

Private Sub CommandButton1_Click()
Run "replace"

End Sub

please help. thanks.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Assigning macro to button

hi
sorry about the other post. hit the wrong button.
try this....

Private Sub CommandButton1_Click()
Call replace
End Sub

regards
FSt1
"Zak" wrote:

I have tried many times to add my macro to a button but it does not work. I
have tried both the control toolbox and the forms menu.

I am in design view when i create the button, double click it to show the
VBE, enter the below code, go back to the button coming out of design view
but nothing happens! not even an error. same when i do it via the forms menu,
i assign the button but nothing happens!!
(replace is my macros name.)

Private Sub CommandButton1_Click()
Run "replace"

End Sub

please help. thanks.

  #5   Report Post  
Posted to microsoft.public.excel.programming
Zak Zak is offline
external usenet poster
 
Posts: 144
Default Assigning macro to button

Hi,

thanks this worked but the problem is it only works when i assign the macro
in the sheet with all the data. if i put the button in sheet 2, which is
empty and where i want the button to be it doesnt work! maybe i need to put
in a condition in the button code so that it works regardless of what sheet
its in. also i found because i put in a condition 'find GIS' (in upper case)
it only finds it if its in upper case, can i do it so the macro will find
this word regardless of the case its in?

thanks a lot.

"FSt1" wrote:

hi
sorry about the other post. hit the wrong button.
try this....

Private Sub CommandButton1_Click()
Call replace
End Sub

regards
FSt1
"Zak" wrote:

I have tried many times to add my macro to a button but it does not work. I
have tried both the control toolbox and the forms menu.

I am in design view when i create the button, double click it to show the
VBE, enter the below code, go back to the button coming out of design view
but nothing happens! not even an error. same when i do it via the forms menu,
i assign the button but nothing happens!!
(replace is my macros name.)

Private Sub CommandButton1_Click()
Run "replace"

End Sub

please help. thanks.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Assigning macro to button

See this site.

http://www.ozgrid.com/News/jan-2006.htm

Unfortunately, you only get one shot to use the assign macro dialog box when
you use the button from the forms toolbar. The button from the Controls
Toolbox allows much more flexibility.

"Zak" wrote:

I have tried many times to add my macro to a button but it does not work. I
have tried both the control toolbox and the forms menu.

I am in design view when i create the button, double click it to show the
VBE, enter the below code, go back to the button coming out of design view
but nothing happens! not even an error. same when i do it via the forms menu,
i assign the button but nothing happens!!
(replace is my macros name.)

Private Sub CommandButton1_Click()
Run "replace"

End Sub

please help. thanks.

  #7   Report Post  
Posted to microsoft.public.excel.programming
Zak Zak is offline
external usenet poster
 
Posts: 144
Default Assigning macro to button

I have used the control toolbox method aswell. how can i get my macro to work
from sheet 2/3/4? at the moment it only works in the sheet with the data in
it.

thanks.

"JLGWhiz" wrote:

See this site.

http://www.ozgrid.com/News/jan-2006.htm

Unfortunately, you only get one shot to use the assign macro dialog box when
you use the button from the forms toolbar. The button from the Controls
Toolbox allows much more flexibility.

"Zak" wrote:

I have tried many times to add my macro to a button but it does not work. I
have tried both the control toolbox and the forms menu.

I am in design view when i create the button, double click it to show the
VBE, enter the below code, go back to the button coming out of design view
but nothing happens! not even an error. same when i do it via the forms menu,
i assign the button but nothing happens!!
(replace is my macros name.)

Private Sub CommandButton1_Click()
Run "replace"

End Sub

please help. thanks.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Assigning macro to button

hi
not sure how you coded the condition. post your code.
and as a thought... you could assign your code to a custom icon. the only
draw back to that is that the sheet button follows the file. costom icons are
unique to the machine.

"Zak" wrote:

Hi,

thanks this worked but the problem is it only works when i assign the macro
in the sheet with all the data. if i put the button in sheet 2, which is
empty and where i want the button to be it doesnt work! maybe i need to put
in a condition in the button code so that it works regardless of what sheet
its in. also i found because i put in a condition 'find GIS' (in upper case)
it only finds it if its in upper case, can i do it so the macro will find
this word regardless of the case its in?

thanks a lot.

"FSt1" wrote:

hi
sorry about the other post. hit the wrong button.
try this....

Private Sub CommandButton1_Click()
Call replace
End Sub

regards
FSt1
"Zak" wrote:

I have tried many times to add my macro to a button but it does not work. I
have tried both the control toolbox and the forms menu.

I am in design view when i create the button, double click it to show the
VBE, enter the below code, go back to the button coming out of design view
but nothing happens! not even an error. same when i do it via the forms menu,
i assign the button but nothing happens!!
(replace is my macros name.)

Private Sub CommandButton1_Click()
Run "replace"

End Sub

please help. thanks.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Assigning macro to button

Hi,
If you write 'call Sheet2.replace' instead of call recplace you will be able
to call code from a diffrent sheet. Sheet2 !)

By the way, you can place you macro in a module instead of in an empty
sheet.

regards,
Lazzzx


"Zak" skrev i meddelelsen
...
Hi,

thanks this worked but the problem is it only works when i assign the
macro
in the sheet with all the data. if i put the button in sheet 2, which is
empty and where i want the button to be it doesnt work! maybe i need to
put
in a condition in the button code so that it works regardless of what
sheet
its in. also i found because i put in a condition 'find GIS' (in upper
case)
it only finds it if its in upper case, can i do it so the macro will find
this word regardless of the case its in?

thanks a lot.

"FSt1" wrote:

hi
sorry about the other post. hit the wrong button.
try this....

Private Sub CommandButton1_Click()
Call replace
End Sub

regards
FSt1
"Zak" wrote:

I have tried many times to add my macro to a button but it does not
work. I
have tried both the control toolbox and the forms menu.

I am in design view when i create the button, double click it to show
the
VBE, enter the below code, go back to the button coming out of design
view
but nothing happens! not even an error. same when i do it via the forms
menu,
i assign the button but nothing happens!!
(replace is my macros name.)

Private Sub CommandButton1_Click()
Run "replace"

End Sub

please help. thanks.


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Assigning macro to button

Zak

Add the line Option Compare Text at the top of the module above your Sub

This tells the code to ignore case.


Gord Dibben MS Excel MVP


On Sun, 13 Jan 2008 09:33:01 -0800, Zak wrote:

Hi,

thanks this worked but the problem is it only works when i assign the macro
in the sheet with all the data. if i put the button in sheet 2, which is
empty and where i want the button to be it doesnt work! maybe i need to put
in a condition in the button code so that it works regardless of what sheet
its in. also i found because i put in a condition 'find GIS' (in upper case)
it only finds it if its in upper case, can i do it so the macro will find
this word regardless of the case its in?

thanks a lot.

"FSt1" wrote:

hi
sorry about the other post. hit the wrong button.
try this....

Private Sub CommandButton1_Click()
Call replace
End Sub

regards
FSt1
"Zak" wrote:

I have tried many times to add my macro to a button but it does not work. I
have tried both the control toolbox and the forms menu.

I am in design view when i create the button, double click it to show the
VBE, enter the below code, go back to the button coming out of design view
but nothing happens! not even an error. same when i do it via the forms menu,
i assign the button but nothing happens!!
(replace is my macros name.)

Private Sub CommandButton1_Click()
Run "replace"

End Sub

please help. thanks.




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Assigning macro to button

If you put the button on a sheet, then the underlying code to the button, as
well as the button, will be attached to that particular sheet. However, you
can put code in the VBA module (Module1 in most cases) that can be called by
the button's code.

Example:

Code underlying button in sheet1.

Private Sub CommandButton1_Click()
sortSh2Data 'Macro name in VBA module
End Sub

Code in VBA module called by button on sheet1 to do task
in sheet2.

Sub sortSh2Data()
Worksheets(2).Range("B1:D50").Sort Key:=Range("B1")
End Sub


Notice that in the VBA module code, that the Worksheet for the code to
execute on is specified (Worksheets(2)). That way there is no confusion as
to where action will take place. If you use Selection or ActiveSheet, you
have to be very careful that the sheet you want the code to execute on is
Selected or Active.

"Zak" wrote:

I have used the control toolbox method aswell. how can i get my macro to work
from sheet 2/3/4? at the moment it only works in the sheet with the data in
it.

thanks.

"JLGWhiz" wrote:

See this site.

http://www.ozgrid.com/News/jan-2006.htm

Unfortunately, you only get one shot to use the assign macro dialog box when
you use the button from the forms toolbar. The button from the Controls
Toolbox allows much more flexibility.

"Zak" wrote:

I have tried many times to add my macro to a button but it does not work. I
have tried both the control toolbox and the forms menu.

I am in design view when i create the button, double click it to show the
VBE, enter the below code, go back to the button coming out of design view
but nothing happens! not even an error. same when i do it via the forms menu,
i assign the button but nothing happens!!
(replace is my macros name.)

Private Sub CommandButton1_Click()
Run "replace"

End Sub

please help. thanks.

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Assigning macro to button

There is a lot of information on this site for beginners. My opinion is that
is about as basic as it gets in explaining VBA programming.

http://www.excel-vba.com/excel-vba-contents.htm

"Zak" wrote:

I have used the control toolbox method aswell. how can i get my macro to work
from sheet 2/3/4? at the moment it only works in the sheet with the data in
it.

thanks.

"JLGWhiz" wrote:

See this site.

http://www.ozgrid.com/News/jan-2006.htm

Unfortunately, you only get one shot to use the assign macro dialog box when
you use the button from the forms toolbar. The button from the Controls
Toolbox allows much more flexibility.

"Zak" wrote:

I have tried many times to add my macro to a button but it does not work. I
have tried both the control toolbox and the forms menu.

I am in design view when i create the button, double click it to show the
VBE, enter the below code, go back to the button coming out of design view
but nothing happens! not even an error. same when i do it via the forms menu,
i assign the button but nothing happens!!
(replace is my macros name.)

Private Sub CommandButton1_Click()
Run "replace"

End Sub

please help. thanks.

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
Assigning a macro to a button hberg Excel Worksheet Functions 1 January 27th 10 10:31 PM
Assigning A Macro to A Button Holly Excel Worksheet Functions 1 January 18th 08 10:04 AM
assigning macro to button BorisS Excel Discussion (Misc queries) 2 September 12th 05 05:08 AM
Assigning macro to button d Excel Discussion (Misc queries) 0 August 22nd 05 01:40 PM
Assigning a macro to a "button" Yvon Excel Discussion (Misc queries) 6 February 8th 05 10:58 PM


All times are GMT +1. The time now is 04:45 PM.

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

About Us

"It's about Microsoft Excel"