Re: Creating a Toggle/Command Button with a Text and Picture underlayer?
.
There are probably several way you can accomplish your goal. The following is just one ....
First, you'll need to have the DEVELOPER tab on your menu bar at the top. If you don't see a tab named DEVELOPER, search the internet for instructions how to show that tab.
You can perform the following on any sheet you desire. For this example we'll presume you are using SHEET 1.
Click DEVELOPER tab / INSERT / under ACTIVEX CONTROLS, select the large "A" which is the icon for an ACTIVEX LABEL. Click it once, then move your mouse
to the cell where you want to place it over. This is the same cell you want to mouse click to perform your Toggle/Command Button action. Left click your mouse and the label
is placed over the cell. You can size the label as needed.
If you have more than one cell you want to do this on, you can create as many ACTIVEX labels as you need, one at a time, repeating these processes.
Right click the label and select PROPERTIES. Change BACKSTYLE to transparent / Delete the CAPTION "Label1" / Make certain VISIBLE is set to TRUE.
Now make certain DESIGN MODE in the menu bar up top is deselected / turned off by clicking on it.
Right click the SHEET 1 tab and select VIEW CODE.
On the left side, double click the Sheet1(Sheet1) name.
In the large code window on the right paste the following :
Code:
Option Explicit
Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
MsgBox "Hi" '<--- this is for testing purposes only. You'll delete this in your final version.
'your macro here or call macro (delete the MsgBox command)
End Sub
Now, go back to Sheet1 and place your mouse pointer over the cell where the ActiveX Label is located. The MessageBox should auto-appear each time your mouse hovers over the cell.
Having the label over the cell will prevent you from using your mouse to navigate to that cell and enter data. You can use the arrow keys (if needed) to make the cell active, then type
what is required into the cell. Any formulas placed in the cell will function normally as well, after the LABEL is placed over the cell.
When you are ready to insert macro code into the above code, comment out or delete the MsgBox line, then insert your macro code. After that, each time your mouse hovers over the cell,
your macro will auto run.
My view is .... it shouldn't be necessary to have a command button appear first. Eliminate that step and simply show a USERFORM with the food data.
Hope this helps.