【发布时间】:2020-10-15 02:38:16
【问题描述】:
这里需要一些帮助...
我需要一些只能删除 9 位(或仅 6-9 位)的东西,然后替换所有空格并用“,”逗号返回 carraige
N6FDT1485 355395112146 355395112146 35539511210 355395112153 35539511214 35539511210 355395112147 3553951121100 355395112110035539511
N6FDC4347 强> 35545111128 355451111269 355451111263 355451111250 355451111260 355451111260 355451111258 355451111258576 3554511112618 355451111151 P>
所以结果如下所示;
355395112146,355395112146,35539511210,355395112153,35539511214,35539511210,355395112147,35539511210,355395112189,355395112100,35545111128,355451111269,35545111126,35545111250,355451111260,35545111160,355451111258,355451111258,35545111126,355451111151 P>
我在下面使用了此代码,但在运行代码之前,我仍然必须先手动删除 N6FDC4347、N6FDT1485 或这 9 位数字的变体..
Sub document_cleanup()
'
' document_cleanup Macro
' Remove trailing spaces and double spaces, tabs, and Enter keys
'
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
' Remove trailing spaces from a paragraph
With Selection.Find
.Text = "^w^v"
.Replacement.Text = "^v"
.Forward = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Remove double spaces
With Selection.Find
.Text = " "
.Replacement.Text = ","
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Remove double tabs
With Selection.Find
.Text = "^t^t"
.Replacement.Text = " ^t"
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Remove double Enter keys (blank paragraphs)
With Selection.Find
.Text = "^p"
.Replacement.Text = ""
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
【问题讨论】:
-
请edit您的问题标题不是重复标签中已有的信息。标题应该描述您遇到的问题或您提出的问题,并且足够清晰,以便对本网站的未来用户扫描搜索结果列表以寻找解决问题的方法有意义。你所做的只是重复标签。
标签: vba search replace ms-word