![]() |
|
|
|
#1
|
|||
|
|||
|
Hi to all,
I'm looking for an equivalent to the "Selection.Bookmarks("\headinglevel")" command because I want to avoid any use of "Selection". Right now I use a nested search with "wdOutlineLevelx" and "ListFormat.ListString" to find the start and end of specific chapters. But that seems to be a rather poor workaround - what if a heading has no ListString … So could you help me out with some more straightforward solution? Thanks a lot NP |
|
#2
|
||||
|
||||
|
You could use Find to locate the heading of interest, then another Find (or a loop)to extend a duplicate range to the start of the next such heading (or the end of the document).
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Hi Paul,
that's excactly what do - maybe my description "Right now I use a nested search" wasn't exact enough .So I guess you don't see another approach ? Thanks NP |
|
#4
|
||||
|
||||
|
Not without use Selection. You could, of course, use something like the following, so your original selection is restored once the macro has finished:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long, Rng As Range
Set Rng = Selection.Range
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.Style = "Heading 2"
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
Do While .Find.Found
i = i + 1
.Duplicate.Select
MsgBox Selection.Bookmarks("\HeadingLevel").Range.Text
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
Rng.Select
Application.ScreenUpdating = True
MsgBox i & " headings found."
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| "Replace all" within a selection (Word 2007) | paulkaye | Word | 5 | 02-19-2013 01:25 AM |
Selection of all Text for a specific page in word is spanning selection across pages
|
ramsgarla | Word VBA | 9 | 12-05-2012 03:23 AM |
Macro VBA "Save as" with bookmarks in file name string
|
Dom37 | Word VBA | 2 | 10-31-2011 03:28 AM |
How to choose a "List" for certain "Heading" from "Modify" tool?
|
Jamal NUMAN | Word | 2 | 07-03-2011 03:11 AM |
| How to fix "create bookmarks using headings" as default when saving to PDF using Word | ghumdinger | Word | 0 | 05-05-2011 02:11 AM |