scrolling text in userform

meraldo

New Member
Joined
Jun 13, 2003
Messages
28
I would like to have about 12 line of text scrolling inside a user form (in a label?). Can this be done?
Thanks for your advise
(y)
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Yes it can be done. You can create a hook to the windows timer event and update the text in your label to create a scrolling effect.


-Mike
 
Upvote 0
Or here is an easier way. Add this code to the UserForm Initialize Event:

Private Sub UserForm_Initialize()
Application.OnTime Now + TimeValue("00:00:01"), "ScrollIt"
End Sub

and add this into a module:

Public Sub ScrollIt()
temp = UserForm1.Label1.Caption
UserForm1.Label1.Caption = UserForm1.Label2.Caption
UserForm1.Label2.Caption = UserForm1.Label3.Caption
UserForm1.Label3.Caption = temp
Application.OnTime Now + TimeValue("00:00:01"), "ScrollIt"
End Sub

-Mike
 
Upvote 0
Hi Meraldo,

Here is a nice way of achieving a Scrolling Text on a UserForm :biggrin: :

You will need to design your Form as follos:

Let's suppose the Form is UserForm1.

Add the following Controls:

Frame1 to serve as a container for the Label .

Label1 to display the scrolling Text. This label should be placed within Frame1.Adjust its position as required.

SpinButton1 to change the Speed of the srolling text.

One CommandButton:ScrlBttn to activate the scrolling.

One CommandButton : StpScrlButtn to halt the Scrolling.

One CommandButton : UnloadFrmBttn to unload the Form.

Note that ,unlike the other controls, the 3 CommandButtons have their names changed for clarity purposes. Rename them via the Property sheet in the VBE at design time.

Ok, that's all for the UserForm design.


Now, let's begin with the Codes and Modules.

Paste this Code in the UserForm1 Module:


<font face=Courier New>
<SPAN style="color:#007F00">'  // Code Purpose:</SPAN>
<SPAN style="color:#007F00">'===================================</SPAN>
<SPAN style="color:#007F00">' Displays a scrolling text on a UserForm and</SPAN>
<SPAN style="color:#007F00">' add other controls to mange the speed of the</SPAN>
<SPAN style="color:#007F00">' scrolling.</SPAN>
<SPAN style="color:#007F00">' The code uses a Class Module to hook the</SPAN>
<SPAN style="color:#007F00">' ccrpTimer Object to which a reference must</SPAN>
<SPAN style="color:#007F00">' be established Via Tools¦References in the</SPAN>
<SPAN style="color:#007F00">' VB Editor.</SPAN>
<SPAN style="color:#007F00">' The ccrpTimer is part of the High-Performance</SPAN>
<SPAN style="color:#007F00">' Timer Objects which can be downloaded from</SPAN>
<SPAN style="color:#007F00">' www.mvps.org/ccrp/download/ccrpdownloads.htm</SPAN>
<SPAN style="color:#007F00">'====================================</SPAN>
<SPAN style="color:#007F00">'  // Code written by Jaafar Cobos on 30/06/03.</SPAN>


<SPAN style="color:#00007F">Dim</SPAN> ClssT <SPAN style="color:#00007F">As</SPAN> Class1
<SPAN style="color:#00007F">Dim</SPAN> ccrpTmr <SPAN style="color:#00007F">As</SPAN> ccrpTimer
    
    
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> UnloadFrmBttn_Click()
        Unload Me
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>

    
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> SpinButton1_SpinDown()
        Beep
        ScrollSpeed = ScrollSpeed / 2
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>

    
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> SpinButton1_SpinUp()
        Beep
        ScrollSpeed = ScrollSpeed * 2
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>

    
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> UserForm_Initialize()

    ScrollSpeed = 1
    msg = "This is a nice scrolling text demonstration !!!"
    
    <SPAN style="color:#00007F">For</SPAN> i = 1 <SPAN style="color:#00007F">To</SPAN> 12
        msg = msg & vbCrLf & msg
    <SPAN style="color:#00007F">Next</SPAN>
    
    Me.Caption = "Scrolling Text Test."
    <SPAN style="color:#00007F">With</SPAN> Label1
        .Caption = msg
        .Font.Bold = <SPAN style="color:#00007F">True</SPAN>
        .ForeColor = vbRed
        .Top = Frame1.Height
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
    
    <SPAN style="color:#00007F">With</SPAN> StpScrlButtn
        .Enabled = <SPAN style="color:#00007F">True</SPAN>
        .Caption = "Stop Label Scrolling"
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
    
    <SPAN style="color:#00007F">With</SPAN> ScrlBttn
        .Enabled = <SPAN style="color:#00007F">False</SPAN>
        .Caption = "Scroll Label"
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
    
    UnloadFrmBttn.Caption = "Unload Form"
    Frame1.Caption = ""
    SpinButton1.Enabled = <SPAN style="color:#00007F">True</SPAN>
    
    <SPAN style="color:#00007F">Set</SPAN> ClssT = <SPAN style="color:#00007F">New</SPAN> Class1
    <SPAN style="color:#00007F">Set</SPAN> ClssT.ccrpTmr = <SPAN style="color:#00007F">New</SPAN> ccrpTimer
    ClssT.ccrpTmr.Enabled = <SPAN style="color:#00007F">True</SPAN>
    ClssT.ccrpTmr.Interval = 10

<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>


<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> ScrlBttn_Click()
    ClssT.ccrpTmr.Enabled = <SPAN style="color:#00007F">True</SPAN>
    SpinButton1.Enabled = <SPAN style="color:#00007F">True</SPAN>
    ScrlBttn.Enabled = <SPAN style="color:#00007F">False</SPAN>
    StpScrlButtn.Enabled = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>


<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> StpScrlButtn_Click()
    ClssT.ccrpTmr.Enabled = <SPAN style="color:#00007F">False</SPAN>
    SpinButton1.Enabled = <SPAN style="color:#00007F">False</SPAN>
    StpScrlButtn.Enabled = <SPAN style="color:#00007F">False</SPAN>
    ScrlBttn.Enabled = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>

</FONT>


Place this at the top of a Standard Module:

<font face=Courier New><SPAN style="color:#00007F">Public</SPAN> ScrollSpeed <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN>
</FONT>


Insert a Class module Class1 in your project and paste the following code in it:


<font face=Courier New><SPAN style="color:#00007F">Public</SPAN> <SPAN style="color:#00007F">WithEvents</SPAN> ccrpTmr <SPAN style="color:#00007F">As</SPAN> ccrpTimer

<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> ccrpTmr_Timer(<SPAN style="color:#00007F">ByVal</SPAN> Milliseconds <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>)

    <SPAN style="color:#00007F">With</SPAN> UserForm1
        <SPAN style="color:#00007F">If</SPAN> .Label1.Top < -.Label1.Height <SPAN style="color:#00007F">Then</SPAN>
                .Label1.Top = .Frame1.Height
        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
        .Label1.Top = .Label1.Top - ScrollSpeed
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>

<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>


As you can see the code makes use of the ccrpTimer object.
If you don't have the ccrpTimer.dll library on your disk try downloading it from here under the High Performance Timer Objects and establish a reference to it via Tools¦References in thr VB editor:

http://www.mvps.org/ccrp/download/ccrpdownloads.htm


Enjoy the scrolling !
 
Upvote 0
Hi meraldo,

If you experience any problems downloading the CcrpTimer dll file from the website above then I can Email you an attachement with the File I have in my disk which works perfectly well.

Regards.
 
Upvote 0
Mike, I have added your code but it does not scroll the text.

Private Sub UserForm_Initialize()
Application.OnTime Now + TimeValue("00:00:01"), "ScrollIt"
End Sub

and add this into a module:

Public Sub ScrollIt()
temp = UserForm1.Label1.Caption
UserForm1.Label1.Caption = UserForm1.Label2.Caption
UserForm1.Label2.Caption = UserForm1.Label3.Caption
UserForm1.Label3.Caption = temp
Application.OnTime Now + TimeValue("00:00:01"), "ScrollIt"
End Sub


Any Ideas?


Thanks for your help.
 
Upvote 0
I downloaded the dll file and pasted it Windows folder. I pasted all the codes given by rafaaj2000 and established a reference to the dll via Too
|References in VB editor bun I am getting a run-time error 429 "ActiveX component can't create object "

Please advise
 
Upvote 0
Mike, I have added your code but it does not scroll the text.

Private Sub UserForm_Initialize()
Application.OnTime Now + TimeValue("00:00:01"), "ScrollIt"
End Sub

and add this into a module:

Public Sub ScrollIt()
temp = UserForm1.Label1.Caption
UserForm1.Label1.Caption = UserForm1.Label2.Caption
UserForm1.Label2.Caption = UserForm1.Label3.Caption
UserForm1.Label3.Caption = temp
Application.OnTime Now + TimeValue("00:00:01"), "ScrollIt"
End Sub


Any Ideas?


Thanks for your help.

Works on mine, just not maybe what you think about as scrolling, since most now think of smooth scrolling.

I think another way to fake this without an additional control is to add a scroll bar to a text box and manipulate the scrollbar value. What I think would work is you make a text box with maybe twice the number of lines you are looking at scrolling, having a second set that repeats the first set. At the end you jump up to the beginning and start over.

Perry
 
Upvote 0

Forum statistics

Threads
1,215,457
Messages
6,124,941
Members
449,197
Latest member
k_bs

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