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

Tip: Looking for answers? Try searching our database.

How to find and delete a Heading with subtext?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hjdietmann@web.de - 04 Mar 2008 12:44 GMT
My Word document consists of several headings with subtext. I want to
find all headings (with the built-in heading style "Heading 4") that
contain a specific keyword (e.g. "TEST") and delete all text under
this heading.
In the example below, I want to delete heading 1.1.1.1 and 1.1.1.3
including the subtext.
In outline view mode, would click on the "+" tag, which highlights the
heading and press the del key.

+  1.1.1.1 -> TEST - Heading
  . Text line 1
  . Text line 2
  . more text

+  1.1.1.2 -> Next Heading
  . Text line 3

+  1.1.1.3 -> TEST - Next Heading
  . Text line 4

How can this be done by a VBA macro?
Thanks for any help.
Hans
Helmut Weber - 04 Mar 2008 16:15 GMT
Hi,

try this one:

Sub Test65523()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
  .Style = "Heading 3"
  While .Execute
     If InStr(rDcm.Text, "TEST") > 0 Then
     rDcm.Select
     Selection.Bookmarks("\headinglevel").Range.Delete
  End If
  Wend
End With
End Sub

which works here and now in case,
there is no further heading that heading 3,
means no heading 4.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
hjdietmann@web.de - 05 Mar 2008 08:45 GMT
> Hi,
>
[quoted text clipped - 25 lines]
>
> Vista Small Business, Office XP

Thank you very much, Helmut.  The code works as expected.
Greetings from Stuttgart, Germany
 
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.