+ -
当前位置:首页 → 问答吧 → 如何用VBA选择文档中的所有数字?

如何用VBA选择文档中的所有数字?

时间:2011-01-10

来源:互联网

文档片段如下:
  G4-1 二氧化碳20,二氧化硫30
想用VBA选择出里面所有的数字,如20(不是2、0)、30(不是3、0),但不包括前面是字母或-的(如这里的4、1)

谢谢。

作者: 振兴中华   发布时间: 2011-01-10

复制内容到剪贴板
代码:
Sub test()
Dim matchs, match
Dim str$
str = "G4-1 二氧化碳20,二氧化硫30"
With CreateObject("vbscript.regexp")
    .Global = True
    .Pattern = "[\u4e00-\u9fa5](\d+)"
    Set matchs = .Execute(str)
    For Each match In matchs
        MsgBox .Replace(match, "$1")
    Next
End With
End Sub

作者: jie-jie   发布时间: 2011-01-10