首页  >  Word

用自定义函数获取文本中的信息

Word 2024-04-15 13:00:14 32

本文为随书问题参考答案

以下过程供参考:

Function MidS(ByVal txt, n As Byte) As String
Application.Volatile True
Dim T As String, i As Long
Dim NumStr As String, EnStr As String, Other As String
For i = 1 To Len(txt)
T = Mid(txt, i, 1)
If T Like "[0-9]" Then
NumStr = NumStr & T
ElseIf T Like "[A-z]" Then
EnStr = EnStr & T
Else
Other = Other & T
End If
Next i
If n = 0 Then
MidS = NumStr
ElseIf n = 1 Then
MidS = EnStr
ElseIf n = 2 Then
MidS = Other
Else
MidS = "#参数错误!"
End If
End Function

VBA 自定义函数
版权声明

本文来自投稿,不代表本站立场,转载请注明出处。

分享:

扫一扫在手机阅读、分享本文