PDA

View Full Version : Solved: How can I prevent Button Double clicks?



frank_m
11-21-2011, 11:07 PM
I need some code that I can add to all of my forms type sheet buttons, that will prevent quick multiple clicks from running the routine multiple times. Possibly a timer if necessary, that will require waiting at least one or two seconds before clicking again. – Something simple, short and sweet, and generic, so that I can use it for most code situations within the button’s assigned macro.

For testing purposes I've attached a sample workbook that has the simplistic macro example shown below, assigned to a button.

Thanks

Sub Macro1()
With ActiveCell
With .Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
.Offset(1, 0).Select
End With
End Sub

frank_m
11-22-2011, 04:54 AM
bump...

hope you don't mind. I'm just am little desperate as I have one procedure for an app. currently in use at my work, that falls down big time if the code runs twice in quick succession by accidentally double clicking the button.

Thanks

nilem
11-22-2011, 05:23 AM
Maybe something like this
Sub Macro1()
Dim shp As Shape
Set shp = ActiveSheet.Shapes(1)
shp.Visible = msoFalse

With ActiveCell
.Interior.ColorIndex = 6
.Offset(1).Select
End With

' here your procedure is working
shp.Visible = msoTrue 'this line is inserted at the end of your procedure
End Sub

frank_m
11-22-2011, 05:52 AM
HI nilem (http://www.vbaexpress.com/forum/member.php?u=42441),

Nice thinking.. Works well.

Thanks