I have a large MS Word userform with a line of a dozen commandbutton click() buttons, which works great. The problem is that when I scroll to a command button, beneath them, those buttons accidentally get activated: resulting in text in my documents getting selected as that is part of the code. Is there a way to delay the click commands so if I just quickly scroll over them they will not get activated and only will when I hoover the mouse on the buttons for a second or so, intentionally?
Private Sub CommandButton162_Click()
If Selection.Type = wdSelectionIP Then
Selection.MoveRight wdCharacter, 1, wdExtend
End If
[additional code]
End Sub
I didn't try anything as I am clueless as to a solution and nothing I have ever encountered before that is solvable, like delaying a macro being called up with an application.ontime code, etc.
I'm assuming the problem is accidental clicks on the buttons (as per @Tim Williams comment, hovering itself won't trigger clicks ... unless you maybe have some accessibility assistance switched on that does that for you?).
All of the following code needs adding to the code-behind of the UserForm (ie where you currently have your
CommandButton162_ClickSub). In this example, I am showing code for only 2 buttons ... but you can replicate the relevant _Click and _MouseMove Subs for your 6 buttons. You will also need to either rename them (eg from 'CommandButton1_Click' to 'CommandButton162_Click' and from 'CommandButton1_MouseMove' to 'CommandButton162_MouseMove' etc) or add them yourself using the drop-downs at the top of the code window (which I guess you did for 'CommandButton162_Click') ... either way, this code won't work without using the right names.I've added comments throughout the code so you can see how it works. The following needs adding at the top of the UserForm, after
Option Explicitand before the first Sub or Function:And this needs adding below, with all other Subs and Functions: