Putting same text for multiple lines

J

Jeff

Hello,

I am very used to Access & Excel VBA. I never worked with Word VBA.

I have 2 questions..

1) How can I reference a specific line ? Meaning for example display a
Msgbox with the text that is on line 57

2) How can I put the same text lets say for 20 lines ?
For r=1 to 20
' what code to write "hello" on each line

Next r

Any help would be greatly appreciated.

Thank you,
Jeff
 
H

Helmut Weber

Hi Jeff,
question 1, if it refers to the main story of a document.
With Selection
.GoTo what:=wdGoToLine, _
which:=wdGoToAbsolute, _
Count:=5
MsgBox .Bookmarks("\line").Range.Text
End With
2) How can I put the same text lets say for 20 lines ?
The problem is _line_ !
As what makes up a line is calculated dynamically,
depending on font, paper size, printer, selection position
and almost everything.
Inserting 20 paragraphs with "some text" could look like this:
Dim i As Integer
With Selection
.ExtendMode = False
.HomeKey unit:=wdLine
For i = 1 To 20
.InsertAfter "some text " & vbCr
Next
End With
---
HTH
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top