如何从 Visual Basic 中的字符串中提取 excel 函数(仅它们的名称)?
例如我有: Sin(B6)*Sum(A2:A4) 所以我想找到一种方法来从中获得“Sin”和“Sum”。
注意:我已经有一个提取单元格地址的代码,它可能会给你一个提示来帮助我。
谢谢你。
Dim result As Object
Dim testExpression As String
Dim objRegEx As Object
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.IgnoreCase = True
objRegEx.Global = True
objRegEx.Pattern = """.*""" ' remove expressions
testExpression = Mystring
testExpression = objRegEx.Replace(testExpression, "")
objRegEx.Pattern = "(([A-Z])+(\d)+)" 'grab the address
Dim i As Long
Dim k As Long
If objRegEx.test(testExpression) Then
Set result = objRegEx.Execute(testExpression)
If result.Count > 0 Then
For Each Match In result
k = Len(Match.value)
i = 1
Do Until (i > k) Or (IsNumeric(Mid$(Match.value, i, 1)))
i = i + 1
Loop
Debug.Print Match.value
Next Match
End if