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 / February 2008

Tip: Looking for answers? Try searching our database.

Macro for selecting text and a diagram that follows it

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
KGollan - 08 Feb 2008 14:36 GMT
I am a beginner with macros, and I am struggling to solve a Word problem with
a macro.

Essentially, I begin with a generated document (from a UML modelling
package)that contains text describing a diagram, and then a diagram. This
document contains around 150 diagrams, structured as above.

I have to write a macro that will find particular types of diagrams (using
the text which is above each diagram) and delete them from the Word document.

Can anyone advise me on the best way to achieve this?

Many thanks,
Katy
Doug Robbins - Word MVP - 13 Feb 2008 00:03 GMT
It depends a bit on how the diagrams are inserted into the document.  That
is, whether they are Shapes or InLineShapes.

But basically, you would use an .Find loop to find the text, then set a
Range to the found text, extend the Range.End to the end of the Range of the
document and then delete the first Shape or InlineShape in that range.  The
code would be something like:

   Dim myrange As Range
   Dim strFind As String
   strFind = "Text to find"
   Selection.HomeKey wdStory
       Selection.Find.ClearFormatting
       With Selection.Find
           Do While .Execute(findText:=strFind, Forward:=True, _
               MatchWildcards:=False, MatchCase:=True, Wrap:=wdFindStop) =
True
               Set myrange = Selection.Range
               myrange.End = ActiveDocument.Range.End
               myrange.ShapeRange(1).Delete
   'or         myrange.InlineShapes(1).delete
               'Now delete the found paragraph
               myrange.Paragraphs(1).Range.Delete
           Loop
       End With
   Next i

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>I am a beginner with macros, and I am struggling to solve a Word problem
>with
[quoted text clipped - 12 lines]
> Many thanks,
> Katy
KGollan - 13 Feb 2008 08:58 GMT
Many thanks Doug, that worked exactly as I had hoped.
Katy

> It depends a bit on how the diagrams are inserted into the document.  That
> is, whether they are Shapes or InLineShapes.
[quoted text clipped - 39 lines]
> > Many thanks,
> > Katy
 
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.