Thread: blinking button
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Leith Ross[_305_] Leith Ross[_305_] is offline
external usenet poster
 
Posts: 1
Default blinking button


Hello Pierre,

Here is a macro than can be used with any button name on any form
Insert a new VBA module into your project and paste the code into.

EXAMPLES OF CALLING BLINKBUTTON MACRO

If you want to blink CommandButton1...
Call BlinkButton(CommandButton1)

If you have 2 UserForms open and want to blink CommandButton1 o
UserForm2...
Call BlinkButton(UserForm2.CommandButton1)

You can make the call from anywhere in your code.


Code
-------------------
'/////////////////////////////////////////'
'/ /'
'/ Sleep suspends program activity /'
'/ for an interval given in Milli- /'
'/ Seconds. 1 millisecond = 1/1000 /'
'/ of a second. /'
'/ /'
'/////////////////////////////////////////'


Public Declare Function Sleep _
Lib "kernel32.dll" _
(ByVal dwMillisecs As Long) As Long

Public Sub BlinkButton(Button As MSForms.Control)

'To use BlinkButton:
'Call BlinkButton(CommandButton1)

Dim N As Long
Dim OrigClr
Dim X As Object
Dim FormName

OrigClr = Button.BackColor
Set X = Button

'Get the Name of the UserForm the button is on
Do
FormName = X.Parent.Name
On Error Resume Next
Set X = X.Parent
If Err.Number < 0 Then
Err.Clear
Exit Do
End If
Loop


'The UserForms collection can only be indexed by a number
For I = 0 To UserForms.Count - 1
If UserForms(I).Name = FormName Then
N = I
Exit For
End If
Next I

'Blink the button - 1/2 second White, 1/2 second Red, 3 times
For I = 1 To 3
Button.BackColor = vbWhite
UserForms(N).Repaint
Sleep (500)
Button.BackColor = vbRed
UserForms(N).Repaint
Sleep (500)
Next I

'Set the button back to it's orignal color
Button.BackColor = OrigClr

End Sub

-------------------

Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=48738