![]() |
|
|
Thread Tools | Display Modes |
#3
|
|||
|
|||
![]()
Graham, Paul,
Thanks for reacting! I knew that I should have used ranges, but before I wrote my message I was using this: HTML Code:
With Selection.Find .ClearFormatting .MatchWholeWord = True .MatchCase = False .ClearHitHighlight .ClearAllFuzzyOptions .Wrap = wdFindContinue ' needed because we don't start from first page .Style = "Heading " & CStr(level) Do While .Execute(FindText:=formStr) If Selection.Paragraphs(1).Range.ListFormat.ListString = headingNumber Then Set myRange = Selection.Paragraphs(1).Range.Duplicate headingFound = True Exit Do End If DoEvents Loop End With after restoring the original range of the selected text. I tried using a range instead, but then the following didn't work as desired: HTML Code:
myRange.Paragraphs(1).Range.ListFormat.ListString HTML Code:
.Parent.Paragraphs(1).Range HTML Code:
With ActiveDocument.Range.Find .ClearFormatting .MatchWholeWord = True .MatchCase = False .ClearHitHighlight .ClearAllFuzzyOptions .Wrap = wdFindContinue ' needed because we don't start from first page .Style = "Heading " & CStr(level) Do While .Execute(FindText:=formStr) Set myRange = .Parent.Paragraphs(1).Range If myRange.ListFormat.ListString = headingNumber Then headingFound = True Exit Do End If DoEvents Loop End With from the following string array: HTML Code:
.GetCrossReferenceItems(wdRefTypeHeading) I search this list for all headings with text that contain my highlighted text, and created a Form that pops up when there is more than 1 match. If there is only 1 header with the exact same text as my selection, then it is automatically selected (no Form shows), and I perform the heading search for the bookmark insertion using that heading number as reference instead of using the header text. Both methods above work, but although it doesn't move the page, the 2nd method with the range is very slightly but noticeably slower than the selection method (I have a large document of about 700 pages here). Thanks again for forcing me to think again about using ranges! p.s. I do the bookmark creation an hyperlink insertion after that. If an existing bookmark exists, I first check its range, to see if it corresponds to that of the header just found. If a bookmark exists, but has different range, then I create a new bookmark by adding a simple index (1,2,...) to the bookmark name. |
Tags |
find focus |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
zhead | Excel | 6 | 09-09-2016 07:52 AM |
Outlook restore from backup didn't seem to find the Calendar. | BudVitoff | Outlook | 0 | 09-08-2015 01:04 PM |
![]() |
lawrencehare | Word | 4 | 11-08-2012 01:08 PM |
![]() |
CabbageTree | Outlook | 2 | 05-14-2012 11:24 AM |
![]() |
cksm4 | Word VBA | 1 | 10-22-2011 11:36 PM |