Keyboard shortcut to change textbox background color

CSyx

Board Regular
Joined
May 2, 2012
Messages
77
Good day all,

Is it possible to assign a keyboard shortcut to change a userform textbox background color? If so, could you please point me in the right direction? The below code works for a textbox when assigned to a command button on the userform. However, it does not work when assigned to a keyboard shortcut.

Code:
If UserForm1.TextBox1.BackColor = &HFFFFFF Then
        UserForm1.TextBox1.BackColor = &HFFFF&
Else
        UserForm1.TextBox1.BackColor = &HFFFFFF
End If

Thanks for the help!
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Here is one way:

Put a control button on your form.
Put your code in for that button.
Here is a shortened version of your code:
Code:
Private Sub CommandButton1_Click()
UserForm1.TextBox1.BackColor = IIf(UserForm1.TextBox1.BackColor = &HFFFFFF, &HFFFF00, &HFFFFFF)
End Sub
Set the Accelerator property to a single letter.
Set the Height and Width of this control button to 0
So if you used t as your accelerator, you would hit Alt-t to run your code.
 
Upvote 0

Forum statistics

Threads
1,214,406
Messages
6,119,330
Members
448,888
Latest member
Arle8907

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