Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Tue, 4 Mar 2008 04:44:44 -0800 (PST),    group: microsoft.public.word.vba.beginners        back       


How to find and delete a Heading with subtext?   
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
date: Tue, 4 Mar 2008 04:44:44 -0800 (PST)   author:   unknown

Re: How to find and delete a Heading with subtext?   
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
date: Tue, 04 Mar 2008 17:15:42 +0100   author:   Helmut Weber

Re: How to find and delete a Heading with subtext?   
On 4 Mrz., 17:15, Helmut Weber  wrote:
> 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


Thank you very much, Helmut.  The code works as expected.
Greetings from Stuttgart, Germany
date: Wed, 5 Mar 2008 00:45:41 -0800 (PST)   author:   unknown

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us