Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-01-18
6
Medium Priority
?
4,826 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
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 …

597 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