#1
|
|||
|
|||
Select Outlinelevel
Hi to all members,
I have a word document, where I have to delete all texts from Outline level 5 ActiveWindow.ActivePane.View.Type = wdOutlineView ActiveWindow.View.ShowHeading 5 Now, How can I Select all heading 5 from a document in wdoutlineview mode. |
#2
|
|||
|
|||
It's not entirely clear what you're trying to do. If you just want to delete the headings, then you can do this without a macro:
|
#3
|
|||
|
|||
Thank you very much for your expertise Peterson, But I am using word 2007 version so select all # instances(s) seems not to exist in word 2007. And I want to select and remove text from heading 5(including heading and texts below heading 5) to the next occurrence of any heading from heading 1 to 5. Thanks in advance.
|
#4
|
|||
|
|||
The following code loops through each paragraph in a doc; if it's H5 style, it's deleted, and any subsequent paragraphs that are either NOT a Heading style OR are H5 or higher are also deleted.
The code isn't working with track changes turned on or if there are redlines in the text and track changes is turned off, and it doesn't catch tables after an H5 heading. This is all I have for now. Code:
Sub Heading5_Delete() ' 01/25/2022 Dim myPara As Paragraph Dim blnHeading5Found As Boolean For Each myPara In ActiveDocument.Paragraphs ' If H5 has been found in a prior loop iteration, ' then check subsequent paragraphs: If blnHeading5Found = True Then ' If the Heading number is 5 or higher... If Mid(myPara.Range.Style, 9, 1) > 4 Then ' ...then delete the paragraph: myPara.Range.Delete ' Or if the style doesn't have "Heading" in it: ElseIf InStr(myPara.Style, "Heading") <> 1 Then ' ...then delete it: myPara.Range.Delete ' Otherwise, reset the "found" variable to false: Else blnHeading5Found = False End If End If ' If the paragraph style is Heading 5: If InStr(myPara.Range.Style, "Heading 5") = 1 Then ' ...then delete it: myPara.Range.Delete ' ...and set the "found" variable to true, in order to ' evaluate subsequent paragraphs: blnHeading5Found = True End If Next myPara End Sub |
#5
|
|||
|
|||
Thanks a lot peterson for your help.
|
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to clear the 'OutlineLevel' property | alex100 | Word VBA | 2 | 06-27-2020 11:47 PM |
Select a row in a different tab | cosmicyes | Excel Programming | 1 | 07-09-2018 02:47 AM |
How to select row | aymanharake | Excel Programming | 3 | 02-18-2017 04:09 PM |
How to select different words at once | FTL | Word | 5 | 03-08-2016 06:10 PM |
select all tables | majed_m | Word VBA | 5 | 07-30-2015 03:29 AM |