Attribute VB_Name = "StringFinder" Option Explicit Public Function CreateStringIndex(ByVal Where As String, ByVal What As String, Optional ByVal Index As Variant) As StringIndex Dim Result As StringIndex Set Result = New StringIndex Result.Where = Where Result.What = What If Not IsMissing(Index) Then Result.Index = CLng(Index) Set CreateStringIndex = Result End Function Public Function Find(ByVal Where As String, ByVal What As String, Optional CaseInsensitive As Boolean) As StringIndex Dim Index As Long Dim Compare As VbCompareMethod If Where = "" Or What = "" Then Set Find = CreateStringIndex("", "") Exit Function End If Compare = IIf(CaseInsensitive, vbTextCompare, vbBinaryCompare) Index = InStr(1, Where, What, Compare) If Index = 0 Then Set Find = CreateStringIndex(Where, What) Else Set Find = CreateStringIndex(Where, What, Index) End If End Function Public Function Between( _ ByVal Where As String, _ ByVal Left As String, _ ByVal Right As String, _ Optional CaseInsensitive As Boolean _ ) As StringIndex Dim First As StringIndex Dim Second As StringIndex Set First = Find(Where, Left, CaseInsensitive) If Not First.Found Then Set Between = First Exit Function End If Set Second = Find(First.After, Right, CaseInsensitive) If Not Second.Found Then Set Between = First Else Set Between = Find(Where, Left & Second.Before & Right, CaseInsensitive) End If End Function