我有一个300多页的Word 2016 doc从另一个程序导入,该程序有大量的表。在每个表格单元格中至少有一个段落标记。我想查找并替换每个段落标记,但只能在表格中(普通文本中有大量其他段落标记,我想单独留下)。
我可以使用“查找/替换”对话框手动执行此操作,但这会占用大量的点击次数和时间。只有表格中没有""对话框中的选项,所以我似乎需要制作一个VBA宏,但我以前从未这样做过。下面是通过记录"在一个表中找到/替换段落标记"的动作而产生的宏。需要更改什么才能使其同时处理所有表格?
Dim mytable As Table
Application.ScreenUpdating = False
For Each mytable In ActiveDocument.Tables
mytable.Range.Editors.Add wdEditorEveryone
Next
ActiveDocument.SelectAllEditableRanges (wdEditorEveryone)
ActiveDocument.DeleteAllEditableRanges (wdEditorEveryone)
Application.ScreenUpdating = True
End Sub
Sub FindReplaceInTable()
'
' FindReplaceInTable Macro
'
'
Selection.Tables(1).Select
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
End Sub
提前致谢。
答案 0 :(得分:0)
尝试:
Sub ClearTblParaBreaks()
Application.ScreenUpdating = False
Dim Tbl As Table
For Each Tbl In ActiveDocument.Tables
With Tbl.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = False
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Text = "[^13]{1,}"
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With
Next
Application.ScreenUpdating = True
End Sub