|
楼主 |
发表于 2020-5-27 10:30
|
显示全部楼层
这是一个删除文本框内回车符的示例代码,也可以改成其他的替换方式。
===================================
Sub d5()
Rem word文本框内文字查找替换
Application.ScreenUpdating = False
On Error Resume Next
'也可用于其他矩形等其他含文字图形的替换
Dim arr()
k = 0
For Each oShp In ActiveDocument.Shapes
ReDim Preserve arr(k)
arr(k) = oShp.Name
k = k + 1
Next
For j = 0 To UBound(arr)
sName = arr(j)
Set oShp = ActiveDocument.Shapes(sName)
Rem 操作画布
If oShp.Type = msoCanvas Then
For n = 1 To oShp.CanvasItems.Count
oShp.CanvasItems(n).TextFrame.TextRange.Find.Execute findtext:="^13", replacewith:="", Replace:=wdReplaceAll, MatchWildcards:=True
Next
End If
Rem 操作组合图形
If oShp.Type = msoGroup Then
For n = 1 To oShp.GroupItems.Count
oShp.GroupItems(n).TextFrame.TextRange.Find.Execute findtext:="^13", replacewith:="", Replace:=wdReplaceAll, MatchWildcards:=True
Next
End If
Rem 操作非画布和非组合图形
If Not oShp.Type = msoGroup And Not oShp.Type = msoCanvas Then
oShp.TextFrame.TextRange.Find.Execute findtext:="^13", replacewith:="", Replace:=wdReplaceAll, MatchWildcards:=True
End If
Next
Application.ScreenUpdating = True
End Sub
|
|