How to insert comment in Word file at page P, line L using VBA

  • Thread starter Peter van de Kerkhof
  • Start date
P

Peter van de Kerkhof

How to insert comment in Word file at page P, line L using VBA

e.g insert text "Demo" on page 3 in line 4

Asumptions:
We have an open active word file.
There are at least 3 pages in the document
Page 3 has at least 4 lines
Insertion of comment preferable at the beginning of the line
(or at a specific token position if possible ?)
Other comment attributes/properties are "don't care"

Regards Peter
 
W

Word Heretic

G'day "Peter van de Kerkhof" <[email protected]>,

with great difficulty son.

First, bookmark all your targets before starting the batch edits as
the lines WILL change when you edit the preceding ones!

Visit these bookmarks in turn and editing them is trivial. The first
bit, not. Thus...

If you use the selection object, you can issue

Selection.HomeKey wdStory,false

to go to the start of the content and then just issue

..movedown commands to move down until your
selection.information(nyahahahah!) stats match up.





Peter van de Kerkhof said:
How to insert comment in Word file at page P, line L using VBA

e.g insert text "Demo" on page 3 in line 4

Asumptions:
We have an open active word file.
There are at least 3 pages in the document
Page 3 has at least 4 lines
Insertion of comment preferable at the beginning of the line
(or at a specific token position if possible ?)
Other comment attributes/properties are "don't care"

Regards Peter

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
Email: (e-mail address removed)
Products: http://www.geocities.com/word_heretic/products.html
Spellbooks: 728 pages of dump left and dropping...

The VBA Beginner's Spellbook: For all VBA users.
 
P

Peter van de Kerkhof

Hi,

As with the next answer, I'm not a VBA expert
The bookmark part I don't get. I assume that entering a word comment
in a line wil not change the position of the the text lay-out. e.g. line
and pages numbers

But we can start at the bottom then, starting with the last line and moving
up to the first.
(I hope this would fix this issue.)

The basics of the loop I understand but not howe to implement them

Can you give me a bit of 'concept' code to help me.

Thanks

PS you're from Down Under?
 
M

martinique

In VBA you iterate a collection like this:

1. Declare a variable of whatever data type the collection contains
(Sentences are Range objects, paragraphs are Paragraph objects).

2. Use the For...each construction to iterate.

Eg

Dim pSentence as Word.Range
For each pSentence in ActiveDocument.Sentences
Debug.Print pSentence.Information(wdActiveEndPageNumber)
next

or

Dim pParagraph as Word.Paragraph
For each pParagraph in ActiveDocument.Paragraphs
....

To get help on a topic like Information, type the word into the immediate
window or a code window and press F1.
 

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