搜索任何标题样式 [英] Search for any heading style

查看:62
本文介绍了搜索任何标题样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个宏,我需要在其中搜索下一个标题的文档(这是一个很长的表)。无论哪种标题样式,无论文档中接下来出现哪个标题都无关紧要。

I'm writing a macro in which I need to search the document (which is one very long table) for the next heading. It doesn't matter which heading style, just whichever heading appears next in the document.

推荐答案

以下应该可以从当前光标位置开始工作表中没有垂直合并的单元格,样式使用内置的标题样式名称。

The following should work, from the current cursor position, provided there are no vertically merged cells in the table and the styles use the built-in heading style names.

Sub NextHeading()
Dim oRng As Range
Dim oCell As Cell
Dim iRow As Integer
    On Error GoTo err_Handler
    If Selection.Information(wdWithInTable) = True Then
        iRow = Selection.Tables(1).Rows.Count
        Set oRng = Selection.Range
        For Each oCell In oRng.Rows(1).Range.Cells
            If oCell.Range.Style Like "Heading*" Then
                If Not oCell.Range.Rows(1).Index = iRow Then
                    oRng.Start = oCell.Range.Rows(1).Range.Next.Rows(1).Cells(1).Range.Start
                    Exit For
                End If
            End If
        Next oCell
        oRng.Start = oRng.Rows(1).Cells(1).Range.Start
        oRng.End = Selection.Tables(1).Range.End
        For Each oCell In oRng.Cells
            If oCell.Range.Style Like "Heading*" Then
                oCell.Select
                Exit For
            End If
        Next oCell
    End If
lbl_Exit:
    Set oRng = Nothing
    Set oCell = Nothing
    Exit Sub
err_Handler:
    Err.Clear
    GoTo lbl_Exit
End Sub


这篇关于搜索任何标题样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆