我有大约 100 行要标记的文本,如下所示:
<word> <unknown number of spaces and tabs> <number>
我无法使用 VBA 找到标记化函数。在 VBA 中标记此类字符串的最简单方法是什么?
您可以逐行阅读并使用 split 功能将单词和数字按空格分开。我依稀记得VBA有拆分功能。
我通过谷歌搜索得到了以下链接。不确定您使用的是哪个版本的office。
http://msdn.microsoft.com/en-us/library/aa155763(office.10).aspx
此链接具有拆分功能。
您可以使用该Split()方法或更复杂的匹配,您可以使用"vbscript.regexp"对象:
Sub NewRegex()
    Dim reg
    Dim matches, match, tmpStr As String
    Set reg = CreateObject("vbscript.regexp")
    tmpStr = "blah bla ...."
    With reg
        .IgnoreCase = True
        .MultiLine = False
        .Pattern = "your regex pattern goes here"
        .Global = True
    End With
    Set matches = reg.Execute(tmpStr)
    For Each match In matches
        MsgBox match
    Next mt
End Sub
这是使用 VBA 中的正则表达式的教程:在 Excel 中使用正则表达式 (RegExp)