Solved

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

Posted on 2014-01-18
6
3,769 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
  • 3
  • 2
6 Comments
 
LVL 26

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 14

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 26

Expert Comment

by:MacroShadow
ID: 39791996
Thank you.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 26

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how to add fields in script 20 43
Paging GridView 7 32
How to open a ZIP file. 6 23
Saveas need to save a copy 16 0
I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now