|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 求和()
Dim rg As Range, str As String, Item As Double, Matches, Match
Set rg = VBA.IIf(Selection.Type = wdSelectionIP, ActiveDocument.Range, Selection.Range)
str = rg.Text
With CreateObject("VBSCRIPT.REGEXP")
.Global = True
.Pattern = "(\-|\+)?\d+(\.\d+)?"
Set Matches = .Execute(str)
For Each Match In Matches
Item = Item + Match.Value
Next
MsgBox "合计:" & Item
End With
With New DataObject
.SetText Item
.PutInClipboard
End With
End Sub |
|