【发布时间】:2021-06-03 23:47:20
【问题描述】:
代替
逗号空格 Anil、逗号空格 Sunil 等
如下图:
、阿尼尔、苏尼尔等
。 我想在同一行中提供序列号,例如:
(1) 阿尼尔 (2) 苏尼尔等
'程序要做很多不必要的工作。有没有更好的方法。
'将光标放在第一个逗号之前的任何位置
Sub GiveSerialToLinerPoints()
x = ActiveDocument.Range(0, Selection.Paragraphs(1). _
Range.End).Paragraphs.Count
i = 0
For Each char In ActiveDocument.Paragraphs(x).Range.Characters
If char = "," Then
i = i + 1
End If
Next char
TotalCommas = i
For i = 1 To TotalCommas
With Selection
.StartIsActive = False
.Extend Character:=","
.Collapse Direction:=wdCollapseEnd
.MoveLeft
.Expand Unit:=wdCharacter
If .Text = "," Then
.Text = " (" & i & ")"
End If
End With
Next i
End Sub
【问题讨论】:
标签: vba ms-word str-replace