Auto Scroll Macro for Word

J

JimK

Hi, I'd like to write a macro so that my 90+ page Word doc will scroll
automatically by itself (for presentation purposes). I'd like it to scroll
about one "line" per hundredth of a second (or so). I've tried the following
code, but that only scrolls for the 0.01 seconds and stops. I'd like it to
continue scrolling at this speed until I hit the macro Shortcut key again
(CTRL+Q). Is there a way to get this scroll speed to continue? And is there
a way to program the macro to recognize that a second entry of the same
Shortcut key will disable the macro? Thanks in advance.

PauseTime = 0.01 ' Set duration.
Start = Timer ' Set start time.
Do Until Timer > Start + PauseTime
'DoEvents ' Yield to other processes.
ActiveWindow.ActivePane.SmallScroll Down:=1
Loop
 
K

Klaus Linke

"JimK"wrote:
Hi, I'd like to write a macro so that my 90+ page Word doc will scroll
automatically by itself (for presentation purposes). I'd like it to
scroll
about one "line" per hundredth of a second (or so). I've tried the
following
code, but that only scrolls for the 0.01 seconds and stops. I'd like it
to
continue scrolling at this speed until I hit the macro Shortcut key again
(CTRL+Q). Is there a way to get this scroll speed to continue? And is
there
a way to program the macro to recognize that a second entry of the same
Shortcut key will disable the macro? Thanks in advance.

PauseTime = 0.01 ' Set duration.
Start = Timer ' Set start time.
Do Until Timer > Start + PauseTime
'DoEvents ' Yield to other processes.
ActiveWindow.ActivePane.SmallScroll Down:=1
Loop


Hi Jim,

Does your mouse have a wheel? You can press it once and then set the
scrolling speed by dragging the mouse.

You can also start/stop that mode with
WordBasic.AutoScroll


With SmallScroll, you don't get the screen to scroll nearly as smoothly.
If you want to try anyhow, something like this with a static Boolean
variable should work:

Static myBool As Boolean
' The second time you run the macro, myBool changes:
myBool = Not myBool
Dim PauseTime, Start
PauseTime = 0.01 ' Set duration.

' I'm not sure that Timer is precise enough.
' Maybe choose PauseTime larger?

Do
Start = Timer ' Set start time.
Do
DoEvents ' Yield to other processes.
Loop Until Timer - Start > 10 * PauseTime
ActiveWindow.ActivePane.SmallScroll Down:=1
Loop Until Not myBool


Regards,
Klaus
 
J

JimK

Thanks very much Klaus. WordBasic.AutoScroll worked like a charm. However,
I'm going to experiment with your Boolean and LoopUntil ideas as well, just
to educate myself. Thank you for your time.
 
J

JimK

Hello, revisiting this one. I'm working in Vista and for some reason the
WordBasic.AutoScroll (or just clicking the mouse wheel to reveal the auto
scroll feature) moves a little too fast and isn't that easy to control the
variable speeds. I've been using the below macro instead, and it's working
well (I've set CTRL+Q to activeate and stop the macro from the document).
But, is there a way for me to add to the macro so that another key (or even
better, a GUI) could add and remove incrimental values to the PauseTime
variable? In this way, I'd be able to speed up or slow down the scroll by
introducing +/- values of 0.01 to the PauseTime variable. Thoughts would be
appreciated. Thank you.

Static myBool As Boolean
myBool = Not myBool
Dim PauseTime, Start
PauseTime = 0.1 ' Set duration (higher number slows scroll down)
Do
Start = Timer ' Set start time.
Do
DoEvents ' Yield to other processes.
Loop Until Timer - Start > 10 * PauseTime
ActiveWindow.ActivePane.SmallScroll Down:=1
Loop Until Not myBool
 
K

Klaus Linke

Hi Jim,

In the macros below, I've used a global variable, PauseTime, for the delay
between the small scrolls.

That variable can then be changed by the two small additional subs
ScrollSpeedUp() and ScrollSlowDown().
For testing, I've used macro buttons for these macros -- you could also
assign different keyboard shortcuts to them.

(Just BTW, I wouldn't use Ctrl+Q myself, since it's by default assigned to a
built-in command I find very useful -- ResetPara to remove manual paragraph
formatting)

The toggling with myBool didn't work well, so I've changed that part. Now
the scrolling stops automatically if the PauseTime is raised above a certain
threshold (currently 1.2 seconds per small scroll).
You can also stop it like any other macro with Ctrl+Pause. Or you can write
an additional macro (assigned to a "stop" button or keyboard shortcut) that
sets PauseTime to a large value, which then causes ScrollStartStop to end
the scrolling.

I've added a display of the scrolling speed to the status bar, below the
document, so one can see whether the scrolling is active, and when it has
been stopped.

It's not terribly elegant. I would have preferred to use OnTime, but
unfortunately that's limited to whole seconds, which is too slow for this
scrolling macro.

I hope you can use or adapt some of the ideas!

Regards,
Klaus



' Put "Dim PauseTime" at the top of the module
' before the first Sub (into the "declaration" section):
Dim PauseTime

Sub ScrollStartStop()
Dim Start

' You can change the "regular" pause between scrolls to some other value:
PauseTime = 0.6

Do
Start = Timer
Do
DoEvents ' Yield to other processes.
Loop Until Timer - Start > PauseTime
ActiveWindow.ActivePane.SmallScroll Down:=1
StatusBar = "Scrolling... " & Format(STR(PauseTime), "0.###")
Loop Until PauseTime > 1.2
StatusBar = "Scrolling: stopped"
End Sub

Sub ScrollSpeedUp()
PauseTime = PauseTime / 1.4
End Sub

Sub ScrollSlowDown()
PauseTime = PauseTime * 1.4
End Sub
 
J

JimK

Klaus, this is perfect. And the Status Bar piece is a great addition.
Thanks VERY much for the help. I appreciate it immensely.
 
K

Klaus Linke

JimK said:
Klaus, this is perfect. And the Status Bar piece is a great addition.
Thanks VERY much for the help. I appreciate it immensely.

Glad it works, and thanks for the feedback!
I still wished there were a (VBA) way to make the screen scoll more
smoothly...

:) Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top