此代码目前发现在目录生成后使用会报错,建议生成目录前使用。
    另,偶有使用后结果有些差异,但目前来看,对于上百页的排版来说,还是比较方便。

    1. Sub word单字成行标红_段落掉字1232314545()
    2. Rem 部分情况下含表格不行会报错
    3. Rem 方便排查单字成行,但需要手动进行进一步处理
    4. Application.ScreenUpdating = False
    5. Dim doc As Document, Rng As Range, Par As Paragraph, lineCount%
    6. Dim LineStart&, LineEnd&
    7. Set doc = ActiveDocument
    8. For Each Par In doc.Paragraphs
    9. lineCount = Par.Range.ComputeStatistics(wdStatisticLines) '段落行数
    10. If Par.Range.Tables.Count = 0 Then 'If Par.Range.Information(12) = False Then
    11. If lineCount > 1 Then
    12. Set Rng = doc.Range(Par.Range.Start, Par.Range.Start)
    13. LineStart = Rng.GoTo(wdGoToLine, wdGoToNext, lineCount - 1).Start
    14. LineEnd = Par.Range.End
    15. If LineStart > LineEnd Then
    16. MsgBox "段落掉字出问题"
    17. Exit Sub
    18. End If
    19. Set Rng = doc.Range(LineStart, LineEnd)
    20. If Len(Rng) <= 3 Then Rng.Font.ColorIndex = wdRed
    21. End If
    22. End If
    23. Next
    24. Application.ScreenUpdating = True
    25. MsgBox "操作完毕!"
    26. End Sub