Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-02-2014, 02:19 AM
NobodysPerfect NobodysPerfect is offline Search in Range Only Problem Windows 8 Search in Range Only Problem Office 2010 32bit
Competent Performer
Search in Range Only Problem
 
Join Date: Jan 2014
Location: Germany
Posts: 136
NobodysPerfect is on a distinguished road
Default Search in Range Only Problem

Hi to all,



I’m looking for a) an explanation and b) for some workaround for the following phenomenon :

Given: A paragraph completely (=incl. paragraph marker) formatted in bold, next paragraph Font.Bold = False
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.
Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.

Selection: First three words of this paragraph.
VBA code:
Code:
Sub RangeFindProblem()
Dim oRng As Range
    Set oRng = Selection.Range
    With oRng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Font.Bold = True
        .Text = ""
        .Replacement.Text = "<start>^&<end>"
        .Forward = True
        .Wrap = wdFindStop
        .Format = True
        .Execute Replace:=wdReplaceAll
    End With
End Sub


Result: Although the range has been set to the first three words only, the complete paragraph (=incl. paragraph marker) has been searched and 'tagged':
<start>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.
<end>Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.

The start of the oRng will always be set correctly according to the selection, but the end will not. The end always seems be set to the very end of the document: all bold passages will be 'tagged'.

I’m a bit confused . I’ve been searching in ranges for many years now, but never noticed that behavior before.

So, first question: Any explanations?
Second question: What can I do to solve this problem?

Thanks for any ideas
NP
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Onenote 2013 search is not identifying search terms correctly Delta223 OneNote 0 08-12-2014 06:40 AM
Search for date and then apply mutliple search criteria in huge dataset maxtymo Excel 2 12-01-2013 04:52 AM
Looking for Windows Search app with ability to search by content gopher_everett Office 1 02-28-2013 09:23 PM
Search Function Problem MageWind Excel 2 06-29-2011 09:46 AM
Search in Range Only Problem Windows explorer search problem...help!! NewSysAdmin Windows 1 03-08-2011 05:33 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:23 AM.


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