VBA: Click and Hold Event

Chris Macro

Well-known Member
Joined
Nov 2, 2011
Messages
1,343
Office Version
  1. 365
Platform
  1. Windows
I am creating a spreadsheet that has various form controls, etc... in it and I wanted to create a "help" macro. I have a small Question Mark icon and I want the user to be able to click the icon and have little text boxes appear on the excel sheet with instructions.

I was wondering instead of making a toggle event where the user clicks once to turn on and again to turn off, if there was a way that the user could click and hold on the icon to make my text boxes visible....and when the user releases they disappear. Just thought it would be a cool effect.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
You can use a Commandbutton and change the caption to a Question Mark, then with a textbox on the sheet use something like below to first hide the textbox, when the sheet is activated, then Show/Hide the textbox with Mousedown /mouseUp event on the Commanbutton.
Code:
Private Sub Worksheet_Activate()
TextBox1.Visible = False
End Sub
Private Sub CommandButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
TextBox1.Visible = True
End Sub
Private Sub CommandButton1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
TextBox1.Visible = False
End Sub
 

Chris Macro

Well-known Member
Joined
Nov 2, 2011
Messages
1,343
Office Version
  1. 365
Platform
  1. Windows
Could I possible use MouseUp/down with and activeX image control?
 

Chris Macro

Well-known Member
Joined
Nov 2, 2011
Messages
1,343
Office Version
  1. 365
Platform
  1. Windows
I was able to get it working with an ActiveX image. Here was the code I used inside the worksheet VBA. Thanks for the huge help!

<font face=Calibri><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> HelpIcon_MouseDown(<SPAN style="color:#00007F">ByVal</SPAN> Button <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>, <SPAN style="color:#00007F">ByVal</SPAN> Shift <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>, <SPAN style="color:#00007F">ByVal</SPAN> x <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Single</SPAN>, <SPAN style="color:#00007F">ByVal</SPAN> y <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Single</SPAN>)<br><br><SPAN style="color:#00007F">Dim</SPAN> BoxNum <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN><br><br><SPAN style="color:#00007F">For</SPAN> BoxNum = 1 <SPAN style="color:#00007F">To</SPAN> 3  <SPAN style="color:#007F00">'# of help comment boxes</SPAN><br><br>Shapes("Help " & BoxNum).Visible = msoTrue<br><br><SPAN style="color:#00007F">Next</SPAN> BoxNum<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> HelpIcon_MouseUp(<SPAN style="color:#00007F">ByVal</SPAN> Button <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>, <SPAN style="color:#00007F">ByVal</SPAN> Shift <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>, <SPAN style="color:#00007F">ByVal</SPAN> x <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Single</SPAN>, <SPAN style="color:#00007F">ByVal</SPAN> y <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Single</SPAN>)<br><br><SPAN style="color:#00007F">Dim</SPAN> BoxNum <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN><br><br><SPAN style="color:#00007F">For</SPAN> BoxNum = 1 <SPAN style="color:#00007F">To</SPAN> 3  <SPAN style="color:#007F00">'# of help comment boxes</SPAN><br><br>Shapes("Help " & BoxNum).Visible = msoFalse<br><br><SPAN style="color:#00007F">Next</SPAN> BoxNum<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,867
Messages
5,834,096
Members
430,260
Latest member
MANICX100

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
Top