1

我无法更改数字格式。我使用 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
4

0 回答 0