Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Macros- adding a pause while auto typing.

Status
Not open for further replies.

ccuurrttiiss

Technical User
Jun 24, 2007
2
GB
Hiya,

I'm completely useless with Visual Basic but this should be pretty easy to do. This is regarding MACROS in Microsoft Word by the way...

Basically I want to open a word document and I would like a sentance to be typed letter by letter.

Then (here's what I am having trouble with) I would like it to pause typing for a given ammount of time EG. 15 seconds before it continues.

Then I would like it to continue writing... How can I put a pause in there?

All it is for is a live comedy routine I am devising whereby I talk to a computer... and it talks back letter by letter (hence the pause). It's that simple!

Your help would be amazing.

Thank you very much.

Jack
 
Have a look at the Timer and DoEvents functions.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I shall look into that. Thank you. Where would this go though?

Here is what I have so far...



Sub testing()

Dim start As Single
Dim message As String

message = "THIS IS THE FIRST BIT OF TEXT TO BE SPELT OUT."
speedupper = 0.02
speedlower = 0.005

Characters = Len(message)

Selection.Font.Name = "Impact"
Selection.Font.Size = 35


For i = 1 To Characters

start = Timer + Rnd((speedupper - speedlower + 1) * Rnd + speedlower)

writing = Mid(message, i, 1)

Selection.TypeText writing

Do While Timer < start
DoEvents
Loop

Next i

End Sub
 
Hmmmm, rather a HUGE font size.....

1. Put the procedure into any code module. You could put it into the existing ThisDocument module, or make a new one to hold it.

2. Could you please use the TGML code tags to put your posted code into a code window? Thanks. Click the Process TGML link for help with this if you need it.

3. Are you using Option Explicit? Your procedure has a number of variables that are not declared. I would recommend you use Option Explicit.
Basically I want to open a word document and I would like a sentance to be typed letter by letter.
Could you clarify this?


Do you want this to be executed automatically when the document is opened?

If not, how do you want it to be started? A button on a toolbar? A keyboard shortcut? A commandbutton in the document itself?

faq219-2884

Gerry
My paintings and sculpture
 
Code:
Sub Print_Message()
   Const message As String = "Hello"
   
   Dim i As Integer
   
   For i = 1 To Len(message)
      Debug.Print Mid(message, i, 1)
      Pause (3)
   Next i
End Sub

Public Sub Pause(seconds As Double)
   Dim start As Long

   start = Timer

   Do Until Timer - start >= seconds
      DoEvents
   Loop
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top