VBA可以用Excel自带的函数呀,用发,Application.WorsheetFunction. 利用Find()找到<style,和style>的位置,然后用Mid截取。 Dim TestStr as string TestStr = "<style ABCDEFGHIJKLMN style>" DIm StaPo as integer StaPo = Application.WorsheetFunction.FIND("<style",TestStr,1) + 6‘你要找的字符长6位 Dim EndPo as integer EndPo = Application.WorsheetFunction.FIND("style>,TestStr,StaPo + 1) Dim MidStr as String'这个就是你要的了 MidStr = Application.WorsheetFunction.Mid(TestStr,StaPo,EndPo-StaPo-6)
Sub abc() Dim reg As Object Set reg = CreateObject("vbscript.regexp") arr = "abcd<styleefghijklmnopstyle>qrstuvwxyz" With reg .Global = True .Pattern = "<style|style>" brr = Split(.Replace(arr, "@"), "@") MsgBox brr(1) & Chr(10) & brr(0) & brr(2) End With Set reg = Nothing End Sub