MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Getting text in a UserForm to flash


Posted by disa on January 17, 2002 12:44 AM

Is there any way of getting text to flash in a UserForm? (Just for special effect?)

I found an example of flashing text in a vb script which used a 'timer'function but when I when to import a copy of the .frm file into my Excel macro I got an error message saying that the Form class was not supported in VBE.Maybe I'm just trying to mix bananas with apples.


Posted by Robb on January 17, 2002 2:58 AM

Disa

Try this code. To test it, you will need to:

- Open a new workbook
- Add a UserForm named UserForm1
- Add a label named Label1 and insert some text
- Paste this code in the code module for the UserForm1


Private Sub UserForm_Initialize()
Call FlashfRM
End Sub

Private Sub UserForm_Terminate()
Call StopItfRM
End Sub

- Then add a module and paste this code

Dim NextTime As Date

Sub FlashfRM()
NextTime = Now + TimeValue("00:00:01")
With UserForm1
If .Label1.ForeColor = RGB(255, 0, 255) Then .Label1.ForeColor = RGB(255, 255, 0) Else .Label1.ForeColor = RGB(255, 0, 255)
End With
Application.OnTime NextTime, "Flashfrm"
End Sub

Sub StopItfRM()
Application.OnTime NextTime, "Flashfrm"
Application.OnTime NextTime, "Flashfrm", schedule:=False
End Sub


Once you've done that, run the UserForm - the initialise event will start the text
flashing - it will stop when you unload the form.

Any help?

Regards

Robb

Posted by Disa on January 17, 2002 5:35 AM

Many thanks Robb - will give it a try.

Posted by Disa on January 17, 2002 10:11 AM

ATTN ROBB: I've tried this but can't get the macro to stop! Any ideas?

Posted by Robb on January 18, 2002 6:55 PM

Disa

It will not stop whilst the UserForm is running, but it should stop when the UserForm is unloaded.

If you want to stop it whils the UserForm is running, include a CommandButton or use the Click event (or some other) of the
UserForm to call the StopItfrm macro.

Any help?

Regards

Robb

ATTN ROBB: I've tried this but can't get the macro to stop! Any ideas?