vba extract text between brackets code example
Example: vba extract text between brackets
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).", "(", ")")
Debug.Print ExtractTag("Value{banana}.", "{", "}")
End Sub