求优化word千分位
这是一个Word宏,用来加千分位并补足小数点后两位的,不过存在一些问题,其中有一个急需解决,那就是这个程序直接无视了小于四位数的数,确实,小于四位数的数不需要加千分位,但是它可能会需要补足小数点后两位,望大佬解决
程序代码:
Sub 加千位符()
'加千位符
Dim i As Range, Acell As Cell, CR As Range
On Error Resume Next
Application.ScreenUpdating = False
If Selection.Type = 2 Then
For Each i In Selection.Words
If i Like "####*" = True Then
If i.Next Like "." = True And i.Next(wdWord, 2) Like "#*" = True Then
i.SetRange Start:=i.Start, End:=i.Next(wdWord, 2).End
i = Format(i, "Standard")
Else
i = Format(i, "Standard")
End If
End If
Next i
ElseIf Selection.Type = 5 Then
For Each Acell In Selection.Cells
Set CR = ActiveDocument.Range(Acell.Range.Start, Acell.Range.End - 1)
MsgBox CR
If CR Like "####*" = True Then
If CR Like "####.#*" = True Then
Yn = Format(CR, "Standard")
CR.Text = Nn
Else
Yn = Format(CR, "Standard")
CR.Text = Nn
End If
End If
Next Acell
Else
MsgBox "只能选定文本或者表格之一", vbOK + vbInformation
End If
Application.ScreenUpdating = True
End Sub









