How to highlight text from the cursor's current position down to aspecific word?

C

cyberdude

Hi,

May I ask how to write a macro that highlights text from the cursor's
current position down to any specific word, let say "name", in the
word document? Then, I want to delete the highlighted text. Thank
you.

Mike
 
H

Helmut Weber

Hi Myke,

like that,
though you won't see much of the highlighting part:

Sub Testb()
Dim x As Long
Dim rDcm As Range
Set rDcm = Selection.Range
x = rDcm.start
rDcm.End = ActiveDocument.Range.End
With rDcm.Find
.Text = "test"
If .Execute Then
rDcm.start = x
rDcm.HighlightColorIndex = wdYellow
rDcm.Delete
End If
End With
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
C

cyberdude

Hi Helmut,

Thank you for your reply very much.

I have been receiving help from the MS Word MVPs here. However, I
don't understand the solution codes that they gave me so I have to
come here to ask again whenever I find problems about Word VBA. May I
ask if there are good Word VBA books that explain the codes and teach
the readers to write the codes in a detail fashion? I really
appreciate the help from all the MVPs here but I don't want to use
their solutions without undestanding them.

Mike
 
H

Helmut Weber

Hi Mike,
May I ask if there are good Word VBA books that
explain the codes and teach the readers to write
the codes in a detail fashion?

I'm sorry, I can't help you with that question.
I got hundreds of books on programming and dare to say,
there is neither a single bad book among them
nor an excellent book, prevailing over all others.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
D

David Sisson

come here to ask again whenever I find problems about Word VBA.  May I
ask if there are good Word VBA books that explain the codes and teach
the readers to write the codes in a detail fashion?  I really

I like Writing Word Macros by Steven Roman via O'Reilly. Kinda dated
now, but I still refer to it regularly.

I also like anything from Guy Hart-Davis.

If I'm in the market for a new VBA book, I always paruse the bookstore
so I can see if I'm getting fluff or meat.
 

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