Flashing textbox

colinharwood

Active Member
Joined
Jul 27, 2002
Messages
440
Office Version
  1. 365
Platform
  1. Windows
Hi

Is it possible to make a textbox on a userform flash by changing its background colour with some code

Thanks a lot
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You haven't provided very much information. So, I'll assume that you have a command button on your userform. I'll also assume that when the command button is pressed, you'd like to check whether there's a value in the textbox before proceeding with your other code. And I'll also assume that if the textbox does not contain a value, you'd like the back color for the textbox to flash red until you click on the textbox.

Place the following code in the module for the UserForm...

Code:
[font=Courier New][color=darkblue]Private[/color] [color=darkblue]Sub[/color] CommandButton1_Click()
    [color=darkblue]If[/color] Me.TextBox1.Value = "" [color=darkblue]Then[/color] [color=darkblue]Call[/color] StartFlashing
    [color=green]'Your Code[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]

[color=darkblue]Private[/color] [color=darkblue]Sub[/color] TextBox1_Enter()
    [color=darkblue]If[/color] Flashing [color=darkblue]Then[/color] [color=darkblue]Call[/color] StopFlashing
[color=darkblue]End[/color] [color=darkblue]Sub[/color]

[color=darkblue]Private[/color] [color=darkblue]Sub[/color] UserForm_QueryClose(Cancel [color=darkblue]As[/color] [color=darkblue]Integer[/color], CloseMode [color=darkblue]As[/color] [color=darkblue]Integer[/color])
    [color=darkblue]If[/color] CloseMode = 0 [color=darkblue]Then[/color]
        [color=darkblue]If[/color] Flashing [color=darkblue]Then[/color] [color=darkblue]Call[/color] StopFlashing
    [color=darkblue]End[/color] [color=darkblue]If[/color]
End [color=darkblue]Sub[/color]
[/font]

Place the following code in a regular module...

Code:
[font=Courier New][color=darkblue]Public[/color] Flashing [color=darkblue]As[/color] [color=darkblue]Boolean[/color]
[color=darkblue]Dim[/color] dtDate [color=darkblue]As[/color] Date

[color=darkblue]Sub[/color] StartFlashing()
    Flashing = [color=darkblue]True[/color]
    [color=darkblue]With[/color] UserForm1.TextBox1
        [color=darkblue]If[/color] .BackColor = RGB(255, 255, 255) [color=darkblue]Then[/color]
            .BackColor = RGB(250, 0, 0)
        [color=darkblue]Else[/color]
            .BackColor = RGB(255, 255, 255)
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]End[/color] [color=darkblue]With[/color]
    dtDate = Now + TimeValue("00:00:01")
    Application.OnTime dtDate, "StartFlashing"
[color=darkblue]End[/color] [color=darkblue]Sub[/color]

[color=darkblue]Sub[/color] StopFlashing()
    Application.OnTime dtDate, "StartFlashing", , [color=darkblue]False[/color]
    UserForm1.TextBox1.BackColor = RGB(255, 255, 255)
    Flashing = [color=darkblue]False[/color]
[color=darkblue]End[/color] Sub
[/font]
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,712
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top