Solved

Word 2010 VBA - Move the cursor one character to the right every 2 seconds

Posted on 2014-01-18
6
4,221 Views
Last Modified: 2014-01-22
I would like to have my cursor move to the right one character every two seconds until the end of document is reached.  At the end of the document, I would like a message box popping up showing the character count and the amount of time elapsed.
What is the Word VBA code to do this?
0
Comment
Question by:brothertruffle880
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39791772
Sub Demo()

    Dim start As Double, delay As Double
    Dim starttime As Double, endtime As Double
    Dim i As Integer


    starttime = Time

    For i = 1 To ActiveDocument.Characters.Count

        start = Timer
        delay = 2

        Selection.Move Unit:=wdCharacter, Count:=1

        Do Until Timer > start + delay
        Loop
    Next i

    endtime = Time

    MsgBox "This document has " & ActiveDocument.Characters.Count & " Characters." & vbCrLf & vbCrLf & "Time elapsed: " & Format(endtime - starttime, "HH:NN:SS")

End Sub

Open in new window

0
 
LVL 15

Expert Comment

by:DrTribos
ID: 39791823
You beat me to it. Nice code - I was thinking of using application.ontime I like your approach  better
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39791996
Thank you.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:brothertruffle880
ID: 39792372
The timer works but the character count is giving me the count for the entire document.    I want a count of the number of characters my cursor is traversing across, Sometimes I'm starting my count in the middle of the document.  I need the count from the start point to the end of the document.
0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39792399
Sub Demo()

    Dim start As Double, delay As Double
    Dim starttime As Double, endtime As Double
    Dim i As Integer


    starttime = Time

    For i = 1 To ActiveDocument.Characters.Count - Selection.Range.start

        start = Timer
        delay = 2

        Selection.Move Unit:=wdCharacter, Count:=1

        Do Until Timer > start + delay
        Loop
        
    Next i

    endtime = Time

    MsgBox "The cursor has moved " & i & " Characters." & vbCrLf & vbCrLf & "Time elapsed: " & Format(endtime - starttime, "HH:NN:SS")

End Sub

Open in new window

0
 

Author Closing Comment

by:brothertruffle880
ID: 39799421
Thank you.  Terrific.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question