vba text between delimiters code example
Example: vba text between delimiters
Function ExtractTag(pSource As String, pOpen As String, pClose As String)
Dim startC As Long, endC As Long
startC = InStr(1, pSource, pOpen) + Len(pOpen)
endC = InStr(1, pSource, pClose)
If startC > 0 And Len(pSource) - startC - (Len(pSource) - endC) > 0 Then
ExtractTag = Mid(pSource, startC, _
Len(pSource) - startC - (Len(pSource) - endC))
End If
End Function
Sub TestMe()
Debug.Print ExtractTag("Weather is [tag]fine[#tag].", "[tag]", "[#tag]")
Debug.Print ExtractTag("Value(banana).", "(", ")")
End Sub