Delete double-mouseclick on a symbolbar icon

K

keksforscher

Hello,

I have a macro assigned to a button in a word XP-symbolbar-icon. A lot
of my users learned in windows to double-click so they always
double-click on the button to execute the macro. Because of the
double-click the macro runs twice. The user doesn't understand why not
double-click. It's hopeless to explain it. I want to catch tis error in
my macro: after the first click the macro is executed. At the end I
want to clear the click/keyboard-buffer to get rid of the second click.
How could this be done?

Thanks

Stefan Westner
 
H

Helmut Weber

Hi keksforscher,

for a pragmatic approach you could include a msgbox
at the start of your macro, like
"Do you really want to do this?"

After the first click, the msgbox has got the focus.
Any further click _anywhere_ else will be ignored.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

Helmut Weber

....
otherwise it will be really complicated.
It isn't the second mouse click,
it is any mouse click later than the first one
within a given time span you want to cancel.

Just for fun, execute every second time:

Sub Macro2()
On Error Resume Next
With ActiveDocument
.Variables.Add "Test", 0
.Variables("Test").Value = _
.Variables("Test").Value + 1
If .Variables("Test").Value Mod 2 <> 1 Then
MsgBox .Variables("Test").Value
' execute your code every second time
End If
If .Variables("Test").Value > 7 Then
.Variables("Test").Value = 0
' there must be an end to everything
End If
End With
End Sub

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
K

Klaus Linke

Helmut Weber said:
otherwise it will be really complicated.
It isn't the second mouse click,
it is any mouse click later than the first one
within a given time span you want to cancel.


You could set a static variable at the end of the macro to the Timer, and
only run the code if more than X seconds have passed:

Static Timer_Old
Select Case Timer - Timer_Old
Case Is < 1
' less than one second: do nothing
Case Else
MsgBox "Run code"
End Select
Timer_Old = Timer


Regards,
Klaus
 
K

Klaus Linke

Oops... won't do if you work around midnight.

Better:

Static Timer_Old
Select Case Timer - Timer_Old
Case 0 To 1
' less than 1 second passed: do nothing
Case Else
MsgBox "Run code"
End Select
Timer_Old = Timer
 
H

Helmut Weber

Hi Klaus,

just for a good lough, ;-)
count seconds from 1.1.1900!
(Double required, long wasn't long enough for me).

Provided excellent hardware
and some accompanying measures

one could limit the execution of a macro
to once in a hundred years.


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top