|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
断行重排 如何利用选择的字数作变量 插入下边的代码
Sub 断行重排()
'先选择较长的一行,再运行代码,使用选择行的字数。
'MsgBox Selection.Characters.Count '显示选择有多少字
ActiveDocument.Content.Find.Execute FindText:=ChrW(160), ReplaceWith:="", Replace:=wdReplaceAll '
ActiveDocument.Content.Find.Execute FindText:="^p([ ]{1,})", MatchWildcards:=True, ReplaceWith:="^p", Replace:=wdReplaceAll
Dim i As Paragraph
On Error Resume Next
Application.ScreenUpdating = False
For Each i In ActiveDocument.Paragraphs
If Len(i.Range) < 25 Then
'------------ 上一句是 小于25个字的段落,如何把25个字 这个变成变量, 变成 ( 'MsgBox Selection.Characters.Count '显示选择有多少字) 选择显示的多少字再减3 --------
i.Range.InsertAfter ChrW(160)
End If
Next
Application.ScreenUpdating = True
ActiveDocument.Content.Find.Execute FindText:="([!。:!?…)])^13", MatchWildcards:=True, ReplaceWith:="\1", Replace:=wdReplaceAll
Selection.WholeStory
With Selection.Find
.Text = (ChrW(160))
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceAll
End With
ActiveDocument.Content.Find.Execute FindText:="([ ]{1,})", MatchWildcards:=True, ReplaceWith:="", Replace:=wdReplaceAll '删除所有空格
'删除所有空段
Selection.WholeStory
With Selection.Find
.Text = "^p^p"
.Replacement.Text = "^p" '
.Execute Replace:=wdReplaceAll
End With
End Sub
见 http://club.excelhome.net/forum.php?mod=viewthread&tid=1509680
|
|