Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-18-2022, 01:21 AM
Bikram Bikram is offline Select Outlinelevel Windows 10 Select Outlinelevel Office 2007
Advanced Beginner
Select Outlinelevel
 
Join Date: Jul 2021
Location: Nepal
Posts: 90
Bikram is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 01-25-2022, 12:40 PM
Peterson Peterson is offline Select Outlinelevel Windows 10 Select Outlinelevel Office 2019
Competent Performer
 
Join Date: Jan 2017
Posts: 141
Peterson is on a distinguished road
Default

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:
  1. Press Ctrl + Alt + Shift + S to show the Styles pane
  2. Hover over the Heading 5 style, then click the down-facing arrow that appears on the right side
  3. Select Select all # instance(s) (for large docs, sometimes the number of instances won't be displayed)
  4. Press the Delete key
Or are you trying to delete just the text that follows a Heading 5 heading? Both the heading AND the text? If also text, how much text? Until the next lower-numbered heading?
Reply With Quote
  #3  
Old 01-25-2022, 07:29 PM
Bikram Bikram is offline Select Outlinelevel Windows 10 Select Outlinelevel Office 2007
Advanced Beginner
Select Outlinelevel
 
Join Date: Jul 2021
Location: Nepal
Posts: 90
Bikram is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 01-26-2022, 12:27 AM
Peterson Peterson is offline Select Outlinelevel Windows 10 Select Outlinelevel Office 2019
Competent Performer
 
Join Date: Jan 2017
Posts: 141
Peterson is on a distinguished road
Default

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
Reply With Quote
  #5  
Old 01-26-2022, 01:32 AM
Bikram Bikram is offline Select Outlinelevel Windows 10 Select Outlinelevel Office 2007
Advanced Beginner
Select Outlinelevel
 
Join Date: Jul 2021
Location: Nepal
Posts: 90
Bikram is on a distinguished road
Default

Thanks a lot peterson for your help.
Reply With Quote
Reply

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 Outlinelevel Select a row in a different tab cosmicyes Excel Programming 1 07-09-2018 02:47 AM
Select Outlinelevel How to select row aymanharake Excel Programming 3 02-18-2017 04:09 PM
Select Outlinelevel How to select different words at once FTL Word 5 03-08-2016 06:10 PM
Select Outlinelevel select all tables majed_m Word VBA 5 07-30-2015 03:29 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:32 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft