PC Review


Reply
Thread Tools Rate Thread

Assigning macro to button

 
 
Zak
Guest
Posts: n/a
 
      13th Jan 2008
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 With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      13th Jan 2008
On the forms (or a shape from the drawing menu)>right click the lower
right>when you see assign macro>just highlight the macro in the vbe


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Zak" <(E-Mail Removed)> wrote in message
news:E4AC5B34-BCDF-4EFD-9E37-(E-Mail Removed)...
>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 With Quote
 
FSt1
Guest
Posts: n/a
 
      13th Jan 2008


"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 With Quote
 
FSt1
Guest
Posts: n/a
 
      13th Jan 2008
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.
>

 
Reply With Quote
 
Zak
Guest
Posts: n/a
 
      13th Jan 2008
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.
> >

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      13th Jan 2008
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 With Quote
 
Zak
Guest
Posts: n/a
 
      13th Jan 2008
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 With Quote
 
FSt1
Guest
Posts: n/a
 
      13th Jan 2008
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.
> > >

 
Reply With Quote
 
Lazzzx
Guest
Posts: n/a
 
      13th Jan 2008
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" <(E-Mail Removed)> skrev i meddelelsen
newsFFE0FBC-E75C-45CB-9EC2-(E-Mail Removed)...
> 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.
>> >


 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      13th Jan 2008
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 <(E-Mail Removed)> 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.
>> >


 
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
Assigning a macro to a button hberg Microsoft Excel Worksheet Functions 1 27th Jan 2010 10:31 PM
Assigning A Macro to A Button Holly Microsoft Excel Worksheet Functions 1 18th Jan 2008 10:04 AM
Assigning a macro to a button outback Microsoft Excel Discussion 5 26th Sep 2007 09:42 PM
assigning a macro to a button =?Utf-8?B?RGFyYnk=?= Microsoft Excel Misc 2 10th Feb 2006 05:05 PM
assigning macro to button =?Utf-8?B?Qm9yaXNT?= Microsoft Excel Misc 2 12th Sep 2005 05:08 AM


Features
 

Advertising
 

Newsgroups
 


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