Selection Object(button) in excel via VBA

prajul89

Active Member
Joined
Jul 9, 2011
Messages
404
I have a button in my sheet which is assigned by a macro.
There are some fields in my sheet that needs to be filled up by user.
Once every fields is filled up I want my change_event macro to select the button, so that just pressing {Enter} or {space} can activate my macro.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Code:
ActiveSheet.Shapes("Button 155").Select

This does not help at all.
It selects my button to Edit mode or design mode.
What I want is, after this selection of button, pressing only {enter} would run the macro assigned to it.

Does anyone know how to do it.
 
Upvote 0
Its a normal Button which I have added in excel sheet and assign it a macro.

I have added it Via Developer TAB > Insert > Form control.........
 
Upvote 0
Why did you choose that type of button instead of an ActiveX Controls button? I didn't think that Forms Controls buttons took focus the way that you want.
 
Upvote 0
I have done what you said I have switched my macro to ActiveX button. Now as far as my knowledge is concerned this should work:
Code:
Me.CommandButton1.Select

But for some reason nothing is happening.
Can you tell me why???
 
Upvote 0
In that case it would be:
Sheet2.CommmandButton1.Activate

.... {space} will run the macro for it.
 
Upvote 0

Forum statistics

Threads
1,224,530
Messages
6,179,373
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top