VBA MS Word更改数字格式

时间:2012-11-30 20:56:42

标签: vba ms-word numbers format

我无法更改数字格式。我使用RegExp并从doc文件中读取数字,但我没有更改格式。评论行是问题。

Sub ChangeNumberFormat()

Dim SectionText As String
Dim RegEx As Object, Matches As Object, Match As Object
Dim i As Integer

Set RegEx = CreateObject("vbscript.regexp")
With RegEx
    .Global = True
    .MultiLine = False
    .Pattern = "(\d{1,3}\s(\d{3}\s)*\d{3}(\,\d{1,3})?|\d{1,3}\,\d{1,3})"
End With

For i = 1 To ActiveDocument.Sections.Count()
    SectionText = ActiveDocument.Sections(i).Range.Text
    If RegEx.Test(SectionText) Then
        Set Matches = RegEx.Execute(SectionText)

        For Each Match In Matches
            **Match = Format(Match, "##,##0.00")**
            MsgBox Match
        Next

        Set MsgMatches = Nothing
        Set    Match = Nothing
     End If
  Next

Set RegEx = Nothing
End Sub

0 个答案:

没有答案