CSDN博客

img JacksonH

去除Word中的回车符

发表于2004/9/16 21:01:00  2616人阅读

分类: Office应用

曾经有个网友问我如何快速地去掉Word文件中选定区域的回车符,花了点时间给做了个宏,感兴趣的朋友可以参考一下,源代码在下面,可以将源码拷到Word中的VB编辑器中,在Word文件中建立一个工具栏按钮运行,源码如下:

Sub Macro1()

Dim i As Integer
Dim j As Integer

i = Selection.Paragraphs.Count - 1

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p"
        .Replacement.Text = " "
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = True
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    For j = 1 To i
        With Selection
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseStart
            Else
                .Collapse Direction:=wdCollapseEnd
            End If
            .Find.Execute Replace:=wdReplaceOne
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseEnd
            Else
                .Collapse Direction:=wdCollapseStart
            End If
            .Find.Execute
        End With
    Next j
End Sub
以上代码是在Word XP下制作的。

0 0

相关博文

我的热门文章

img
取 消
img