Function stxtRow(ByVal sStr As String, ByVal nRow As Long, Optional ByVal sP1 As String = vbCrLf, Optional ByVal sP2 As String = vbCrLf) As String
Dim x As Long '循環用
Dim nPoint1 As Long '保存第壹個關鍵點
Dim nPoint2 As Long '保存第二個關鍵點
Dim tnRow As Long '保存默認情況時的 尋找位置號
Dim isDef As Boolean
If sP1 = sP2 Then isDef = True Else isDef = False
For x = 1 To nRow
nPoint1 = InStr(nPoint1 + 1, sStr, sP1)
nPoint2 = InStr(nPoint1 + Len(sP1), sStr, sP2)
'Debug.Print nPoint1, nPoint2
If isDef Then tnRow = nRow - 1 Else tnRow = nRow
If isDef And nPoint2 = 0 And sP2 = vbCrLf Then nPoint2 = Len(sStr) + Len(sP1)
If nPoint1 = 0 Or nPoint2 = 0 Then
If isDef Then
stxtRow = "": Exit Function
'stxtRow = "沒有找到,文件***" & x & "行": Exit Function
Else
stxtRow = "": Exit Function
'stxtRow = "沒有找到,文件***" & x - 1 & "行": Exit Function
End If
End If
If nRow = 1 And isDef And sP2 = vbCrLf Then '如果默認搜頭壹行
stxtRow = Mid(sStr, 1, nPoint1 - 1)
Exit Function
Else '其他情況
If x = tnRow Then
stxtRow = Mid(sStr, nPoint1 + Len(sP1), nPoint2 - nPoint1 - Len(sP1))
Exit Function
End If
End If
Next
End Function
比如字符串s="ksdjfkls我slkjfsd說sdfsdf" 妳要提取我說中間的
stxtRow s,1,"我","說"
這是提取s中 我開頭 說結尾的第壹個字符串,代碼寫的亂但肯定能用