Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 01-19-2021, 02:09 PM
gmaxey gmaxey 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
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

For a common process, you could make the docCurrent a module level variable and then pass arguments to:


Code:
Sub ProcessTable(oTbl As Table, strStartWord As String, strEndWord As String, strUser As String)
Dim oRng As Row
Dim strKeyword As String, strRule As String
  For Each oRow In oTbl.Rows
    strKeyword = Split(Trim(oRow.Range.Cells(1).Range.Text), vbCr)(0)
    strRule = Split(Trim(oRow.Cells(2).Range.Text), vbCr)(0)
    If strKeyword <> "" Then
      Set oRng = GetDocRange("DETAILED", "CLAIMS") 'make docCurrent a module level varialbe
      Set oRngScope = oRng.Duplicate
      With oRng.Find
        .Text = strKeyword
        Do While .Execute
          If Not oRng.InRange(oRngScope) Then Exit For
          oRng.HighlightColorIndex = wdTurquoise
          If strRule <> "" Then
            Set cmtRuleComment = m_oDocCurrent.Comments.Add(Range:=oRng, Text:=strUser & ": " & strRule)
            cmtRuleComment.Author = UCase("WordCheck")
            cmtRuleComment.Initial = UCase("WC")
          End If
        Loop
      End With
    End If
  Next oRow
End Sub
Function GetDocRange(startWord As String, endWord As String) As Range
Dim oRng As Word.Range, iStart As Long, iEnd As Long
  Set oRng = m_oDocCurrent.Range
  With oRng.Find
    .Text = startWord
    If .Execute Then iStart = oRng.End
    oRng.End = aDoc.Range.End
    .Text = endWord
    If .Execute Then iEnd = oRng.Start
    If startWord = "ABSTRACT" Then iEnd = aDoc.Range.End
    If iEnd > iStart Then
      Set GetDocRange = aDoc.Range(iStart, iEnd)
    End If
  End With
End Function
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 



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 09:31 PM.


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