PDA

View Full Version : Solved: help with word scrolling macro



hawk
06-11-2008, 05:49 PM
the scrolling of the document is to be controlled by the macro
at the moment it scrolls with hesitation due to the api call to sleep()

what I would like to do is smooth the scroll action

heres the code

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub PScroller()


'set counter n to documnet len'

n = ActiveDocument.Paragraphs.Count

'setup Document

ActiveWindow.ActivePane.View.Zoom.Percentage = 130
ActiveWindow.ActivePane.DisplayRulers = False
ActiveDocument.FormattingShowParagraph = False
ActiveDocument.ShowSpellingErrors = False
ActiveDocument.ShowGrammaticalErrors = False

MsgBox "Marco is ready to run, click on ok to continue", vbOKOnly

'Main loop. controls how many times scrolled
For a = 0 To 9 ' loops 10 times

'increments scroll
Do

ActiveWindow.ActivePane.VerticalPercentScrolled = i
' 1000 of a secound, pauses loop
Sleep (1)
i = i + 1

Loop While n > i

'Return to top of page and start again. reset i for next loop
Selection.HomeKey Unit:=wdStory
i = 0
Next a

MsgBox "Marco run finsihed", vbOKOnly

'reset defaults
ActiveWindow.ActivePane.DisplayRulers = True
ActiveDocument.ShowSpellingErrors = True
ActiveDocument.ShowGrammaticalErrors = True

End Sub
Im new to this so any help would be good

qazpl
06-12-2008, 08:56 AM
Why are you incrementing sleep. It should be sleep(1).

hawk
06-12-2008, 10:27 AM
Thanks qazpl, you're right fixed now but still a jerky scroll ie move wait move wait. I would like it to be smooth consistant read speed scoll.

qazpl
06-13-2008, 06:45 AM
With ActiveDocument.ActiveWindow.ActivePane /n Do /n .SmallScroll /n Sleep 1 /n Loop While .VerticlePercentScrolled < 95 /n End With

hawk
06-13-2008, 03:54 PM
qazpl, you are a star, Thank You :beerchug:

I changed from the sleep to a timer procedure Hadn't had a chance to post up the code when I relizied you had replyed, Sorry for that.

Heres the snippet you provided with the timer code included

With ActiveDocument.ActiveWindow.ActivePane
Do
.SmallScroll
PauseTime = 3 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other process
Loop
Loop While .VerticalPercentScrolled < 95
End With
I think the timer (thanks to vba help) gives more control than the sleep event

Once again thank you