Moving the cursor to a selection

D

Devin Rader

I have a macro that uses the Find object to locate each instance of a
particular Style. When an instance of the Style is found, I would like to
move the cursor to the selection to that I can select the surrounding range
and delete it. The macro is at the end of the message.

Thanks

devin



Dim index As Integer
Dim rngToSrch As Range
Dim rngResult As Range

' Set search ranges
Set rngToSrch = ActiveDocument.Range
Set rngResult = rngToSrch.Duplicate
index = 0

Do
With rngResult.Find
.ClearFormatting
.Style = "InstructorLead"
.Text = ""
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
.Execute
End With

' Exit loop if not found
If Not rngResult.Find.Found Then
MsgBox ("No Matches Found")
Exit Do
End If

index = index + 1

' how to move the cursor to the found selection??
' once the cursor is moved, select the surrounding range of text
' delete the selected range

' Prepare for next search by
' moving the start position over one word
rngResult.MoveStart wdWord
' and extending the end of rngResult
rngResult.End = rngToSrch.End

Loop Until Not rngResult.Find.Found

MsgBox ("total matches found: " & index)
 
H

Helmut Weber

Hi Devin,
move the cursor to the selection to that I can select the surrounding range
and delete it. The macro is at the end of the message.

What is the "surrounding range"?

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
D

Devin Rader

Basically this is my scenerio:

We have a set of docs that we use for training. We are going to introduce
an online version of our training using the same docs as our current
instructor lead docs, but since some of the content in the instructor lead
version of the docs is not relavent in the online version, what I want to do
is somehow be able to determine what section are Instructor Lead specific
content, and use a macro to delete those sections when we need to printthe
online versions.

I am trying to do all of this work in one set of "working docs" so that I do
not have to duplicate the content and maintain both "instructor lead" and
"online" versions of the training materials, thats why I would like to have
a macro simply that removes the content.

Is there a good way to do this?

devin
 
H

Helmut Weber

Hi Devin,

hm..., well...
I am trying to do all of this work in one set of "working docs" so that I do
not have to duplicate the content and maintain both "instructor lead" and
"online" versions of the training materials, thats why I would like to have
a macro simply that removes the content.

You can search for almost everything and remove almost
everything, except the last paragraph mark, but you still
have to define, what you want to remove in a way,
understandable to Word. Word does not know "surrounding range",
yet it knows "content", but this is all of the doc. (?)

I'm sorry, so far.


Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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