谢谢老大。 我的目的确实是为了整理,可能我在6楼没将意图讲清楚,导致老大可能误会我的意思了。我是想复制帮助文件相关内容后运行该宏即可完成粘贴及对粘贴部分文本的处理,而对文档原来的部分不作处理。 我试着写了如下测试代码,执行后基本可以处理,但还有些问题未能解决,如:没有保留原粘贴超带链接文本的颜色,有时执行时好像没有在活动文档进行,运行时间稍长,等等。不知如何修改简化才好。 Sub paste_helpfile()
'此宏用于整理从帮助文件粘贴来的文本 '复制帮助文件后运行本过程 ' Dim myRange As Range, mytabl As Table, mypara As Paragraph, mycell As Cell Dim i As Integer, myfind As Variant, myreplace As Variant Dim starttime As Single, endtime As Single 'starttime = Timer If Selection.Type <> wdSelectionIP Then MsgBox "当前所选内容不是插入点!", vbCritical Exit Sub End If Application.ScreenUpdating = False Set myRange = Selection.Range Selection.Paste '设定查找替换的项目 myfind = Array("^g", "[^32^s]{1,}^13", "^13{3,}", "<参阅*^13", "<(注意)^32", _ "([A-z])^32([一-龥])", "([一-龥 ])^32([A-z])", "全部显示", "全部隐藏") myreplace = Array("", "^p", "^p^p", "", "\1 ", "\1\2", "\1\2", "", "") myRange.SetRange Start:=myRange.Start, End:=Selection.End With myRange .Select .Fields.Unlink '取消域链接 '执行查找替换 For i = 0 To UBound(myfind) With .Find .ClearFormatting .MatchWildcards = True .Text = myfind(i) .Replacement.ClearFormatting .Replacement.Text = myreplace(i) .Execute Replace:=wdReplaceAll End With Next '设置段落格式 With .ParagraphFormat .LeftIndent = CentimetersToPoints(0) .RightIndent = CentimetersToPoints(0) .SpaceBefore = 0 .SpaceBeforeAuto = False .SpaceAfter = 0 .SpaceAfterAuto = False .LineSpacingRule = wdLineSpaceSingle .LineUnitBefore = 0 .LineUnitAfter = 0 End With '处理表格格式、宽度、及单元格内对齐 If .Tables.Count > 0 Then For Each mytabl In .Tables With mytabl .Style = "网格型" .PreferredWidthType = wdPreferredWidthPercent .PreferredWidth = 95 For Each mycell In .Range.Cells If mycell.ColumnIndex = .Columns.Count _ And mycell.RowIndex > 1 Then mycell.Range.ParagraphFormat.Alignment = wdAlignParagraphLeft Else mycell.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter End If Next End With Next End If '设置段落字号大小 For Each mypara In .Paragraphs If mypara.OutlineLevel = wdOutlineLevel1 Then mypara.Range.Font.Size = 15 '一级大纲级别段落为小三号 ElseIf mypara.OutlineLevel = wdOutlineLevel2 Then mypara.Range.Font.Size = 14 '二级为四号 Else mypara.Range.Font.Size = 12 '三级为小四 End If Next Application.ScreenUpdating = True '将插入点置于新粘贴的文本之后 .SetRange Start:=.End, End:=.End .Select End With 'endtime = Timer 'Debug.Print endtime - starttime End Sub
[此贴子已经被作者于2007-3-17 11:24:02编辑过] |