Solved

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

Posted on 2014-01-18
6
4,436 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

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 article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 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