如何在 Microsoft Word 中将制表符转换为缩进符

如何在 Microsoft Word 中将制表符转换为缩进符

将文本从其他编辑器复制粘贴到 Microsoft Word 时,段落开头带有制表符。如何将其转换为段落缩进,以获得更好的格式?

答案1

我发现最好的方法是编写 VBA 宏。

它可能没有针对性能进行优化,但它可以完成工作。=)

Sub ConvertLeadingTabsToIndents()
    On Error GoTo Error

    Application.ScreenUpdating = False

    Dim found As Boolean

    found = FindNextTab()
    While (found)
        Selection.MoveRight Unit:=wdCharacter, Count:=1
        Selection.TypeBackspace
        Selection.Paragraphs.Indent

        found = FindNextTab()
    Wend

    MsgBox "Success!", vbInformation

Exit_Sub:
    Exit Sub

Error:
    Application.ScreenUpdating = True
    ' Regenerate original error.
    Dim intErrNum As Integer
    intErrNum = Err
    Err.Clear
    Err.Raise intErrNum
End Sub

Function FindNextTab()
    With Selection.Find
        .Text = "^p^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
    End With
    FindNextTab = Selection.Find.Execute
End Function

相关内容