Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-14-2015, 05:55 AM
NobodysPerfect NobodysPerfect is offline Selection.Bookmarks("\headinglevel") WITHOUT Selection Windows 8 Selection.Bookmarks("\headinglevel") WITHOUT Selection Office 2010 32bit
Competent Performer
Selection.Bookmarks("\headinglevel") WITHOUT Selection
 
Join Date: Jan 2014
Location: Germany
Posts: 136
NobodysPerfect is on a distinguished road
Default Selection.Bookmarks("\headinglevel") WITHOUT Selection

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
Reply With Quote
  #2  
Old 01-14-2015, 06:44 AM
macropod's Avatar
macropod macropod is offline Selection.Bookmarks("\headinglevel") WITHOUT Selection Windows 7 64bit Selection.Bookmarks("\headinglevel") WITHOUT Selection Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 01-14-2015, 07:24 AM
NobodysPerfect NobodysPerfect is offline Selection.Bookmarks("\headinglevel") WITHOUT Selection Windows 8 Selection.Bookmarks("\headinglevel") WITHOUT Selection Office 2010 32bit
Competent Performer
Selection.Bookmarks("\headinglevel") WITHOUT Selection
 
Join Date: Jan 2014
Location: Germany
Posts: 136
NobodysPerfect is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 01-14-2015, 12:58 PM
macropod's Avatar
macropod macropod is offline Selection.Bookmarks("\headinglevel") WITHOUT Selection Windows 7 64bit Selection.Bookmarks("\headinglevel") WITHOUT Selection Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply



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.Bookmarks("\headinglevel") WITHOUT Selection 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
Selection.Bookmarks("\headinglevel") WITHOUT Selection Macro VBA "Save as" with bookmarks in file name string Dom37 Word VBA 2 10-31-2011 03:28 AM
Selection.Bookmarks("\headinglevel") WITHOUT Selection 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

Other Forums: Access Forums

All times are GMT -7. The time now is 12:57 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