New to Word VBA

B

Brad Hale

Hi all,

I have written macros in Excel before but not Word...and it doesn't seem to
be as easy.
I need to find all instances of highlighted text in a document and copy each
entry through to excel.

I have managed to work out (through the recorder) how to find the
highlighted text....but not sure how to count the occurances of the
highlighted objects for the loop.

Once I have the count I can loop through but not sure about how to export to
either excel directly or to a dump file for import to excel.

Thanks in advance

Brad
 
M

Michael Bednarek

I have written macros in Excel before but not Word...and it doesn't seem to
be as easy.
I need to find all instances of highlighted text in a document and copy each
entry through to excel.
[snip]

Maybe this can help:

ActiveDocument.Select
With Selection.Find
.ClearFormatting
.Highlight = True
Do While .Execute = True
Debug.Print Selection.Words(1)
' ... and whatever else you need to do ...
Loop
End With
 
D

David Sisson

I have written macros in Excel before but not Word...

I know what you mean. I'm doing the reverse. I've had my new Excel
books out today trying to solve a logic problem.
.....but not sure how to count the occurances of the
highlighted objects for the loop.

Just count as you go.
'Pseudo code
do
Find Highlighted
If Find.found
Counter = Counter + 1
ReDim MyArray(Counter) Preserve
MyArray(Counter) = Highlighted
End if
loop said:
Once I have the count I can loop through but not sure about how to export to
either excel directly or to a dump file for import to excel.

http://word.mvps.org/faqs/interdev/ControlXLFromWord.htm

Then you probaby can pass the whole array as a range to Excel. (But
don't quote me on that.)

David
 

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