Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-21-2021, 01:37 PM
rekent rekent is offline Find code is ignoring MatchCase flag and range end being incorrectly set Windows 10 Find code is ignoring MatchCase flag and range end being incorrectly set Office 2016
Novice
Find code is ignoring MatchCase flag and range end being incorrectly set
 
Join Date: May 2014
Posts: 23
rekent is on a distinguished road
Default

Tracked it down. GetDocRange was returning an incorrect value for oRng because when the SUMMARY section was missing, "SUMMARY" was not found and lngStart remained at zero. But the next section header "DRAWINGS" was found, creating a range from document start to the beginning of "DRAWINGS." The nested If statements at the end of this function seem to do the trick, and I haven't been able to come up with a scenario yet in which they break other functionality.

Code:
Function GetDocRange(startWord As String, endWord As String) As Range
Dim oRng As Word.Range, lngStart As Long, lngEnd As Long
  Set oRng = m_oDocCurrent.Range
  With oRng.Find
    .Wrap = wdFindStop
    .MatchCase = True
    .Text = startWord
    If .Execute Then lngStart = oRng.End
    oRng.End = m_oDocCurrent.Range.End
    .Text = endWord
    If .Execute Then lngEnd = oRng.Start
    If startWord = "ABSTRACT" Then lngEnd = m_oDocCurrent.Range.End
    If lngStart = "0" Then
      Set GetDocRange = m_oDocCurrent.Range(lngStart, lngStart)
    Else
      If lngEnd > lngStart Then
        Set GetDocRange = m_oDocCurrent.Range(lngStart, lngEnd)
      End If
    End If
  End With
End Function

Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find code is ignoring MatchCase flag and range end being incorrectly set Range method Find can't find dates jmcsa3 Excel Programming 1 05-02-2020 06:56 AM
Find code is ignoring MatchCase flag and range end being incorrectly set Find if Date range falls within another range Triadragon Excel 3 05-02-2016 11:48 AM
Find a Date in a Range rspiet Excel 3 02-15-2016 08:37 AM
find IP in range / find number between numbers gn28 Excel 4 06-14-2015 03:46 PM
Find and Replace within range anil3b2 Word VBA 3 12-01-2010 02:35 AM

Other Forums: Access Forums

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