Private Function GetBetween(ByRef sSearch As String, _
ByRef sStart As String, _
ByRef sStop As String, _
Optional ByVal lSearch As Long = 1, _
Optional ByVal bCaseSensitive As Boolean = True) As String
Dim lonS As Long, lonE As Long
Dim strLCSearch As String
Dim strLCStart As String, strLCStop As String
'Case-sensitive...
If bCaseSensitive Then
lonS = InStr(lSearch, sSearch, sStart)
If lonS Then
lonS = lonS + Len(sStart)
lonE = InStr(lonS, sSearch, sStop)
If lonE Then
GetBetween = Mid$(sSearch, lonS, lonE - lonS)
End If
End If
'Not case-sensitive
'Faster to convert string to lowercase rather than vbTextCompare
Else
strLCSearch = LCase$(sSearch)
strLCStart = LCase$(sStart)
strLCStop = LCase$(sStop)
lonS = InStr(lSearch, strLCSearch, strLCStart)
If lonS Then
lonS = lonS + Len(strLCStart)
lonE = InStr(lonS, strLCSearch, strLCStop)
If lonE > 0 Then
GetBetween = Mid$(sSearch, lonS, lonE - lonS)
End If
End If
End If
End Function