Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternate Text on A Command Button

Status
Not open for further replies.

Worsty

Programmer
Oct 27, 2004
34
US
Does anyone know if you can add alternate text on a command button so that if you hover over the button it will display the alternate text?

Any help would be greatly appreciated.
 
Have a look at the ControlTipText property of the CommandButton object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I'm using the Control Toolbox command button in Excel and I've looked through the properties and do not see the above property. Sorry, maybe I'm missing something.
 
I talked about a MSForm CommandButton.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks, but I'm not using a VBA Form, just drawing the command button right onto the spreadsheet.
 
Worsty,

Try something like the following event code, which is entered in the code module of the worksheet containing the CommandButton:
Code:
Private Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
   With CommandButton1
     If X > 2 And X < (.Width - 2) And Y > 2 And Y < (.Height - 2) Then
       .Caption = "Alternate Caption"
     Else
       .Caption = "Original Caption"
     End If
   End With
End Sub

This isn't a perfect solution since moving the mouse rapidly over the CommandButton will sometimes leave the Alternate Caption displayed. Experiment with changing the value of 2. Larger values lessen the occurrence of that problem but create larger border zones within the button where no caption change takes place.

Hope this helps,
Mike
 
I am OK with the command button, my form has a cancel command button which changes the pointer to vbdefault when the mouse is over it,

but I want to make it change when the pointer is over the "x" button (Unload button - top right corner of the form)
 
Mike:
Thanks for the code, but I got the following to work for me.

Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer

Const VK_LEFT = &H25
Const VK_UP = &H26
Const VK_RIGHT = &H27
Const VK_DOWN = &H28
Const VK_RETURN = &HD
Const VK_TAB = &H9



Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = Range("c8").Address Then '\\\ Change this Cell as requiered !
If GetKeyState(VK_UP) >= 0 And GetKeyState(VK_DOWN) >= 0 _
And GetKeyState(VK_LEFT) >= 0 And GetKeyState(VK_RIGHT) >= 0 _
And GetKeyState(VK_TAB) >= 0 And GetKeyState(VK_RETURN) >= 0 Then
'MsgBox " You clicked on Cell : " & Target.Address, vbInformation

Put the rest of your code to complete the function below.

Maybe this will help someone else also!

 
By the way, I forgot to mention that I removed the button and am using this code for a particular cell, making the cell appearance to look like a button.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top