Function CutR(str As String, endStr As String, getLen As Integer) As String 'CutR函數 '截取文本中指定開始字符,指定長度的字符串,如截取編號等 'str: 文本 'endStr: 目標字符串 , 或者編號的標識符 'getLen: 要截取的長度 '返回值: 指定長度的字符 Dim e As Integer e = InStr(str, endStr) + Len(endStr) If e < 0 Then CutR = "" Else CutR = Mid(str, e, getLen) End If End Function
'測試 得到36個字符長度的 45706EC7-5B31-48FD-A75D-00005A08C27D
Sub test() Dim str As String str = CutR("sadlaskdajdkajkGuidNo:45706EC7-5B31-48FD-A75D-00005A08C27D********", "GuidNo:", 36) Debug.Print str Debug.Print Len(str) End Sub