Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2005

Tip: Looking for answers? Try searching our database.

Moving the cursor to a selection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Devin Rader - 01 Aug 2005 21:37 GMT
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)
Helmut Weber - 01 Aug 2005 22:25 GMT
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"
Devin Rader - 01 Aug 2005 23:13 GMT
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

> Hi Devin,
>
[quoted text clipped - 10 lines]
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
Helmut Weber - 02 Aug 2005 16:10 GMT
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"
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.