删除Word中标题的宏

发布于 2024-07-28 23:23:46 字数 122 浏览 1 评论 0原文

我有一个 WORD 文档,其中有许多 H1 标题。 我想要一个宏,允许我删除从特定 H1 标题到下一个 H1 标题的所有内容 - 本质上是删除 H1 部分。 同样,我可能想从 H2 标题中删除直到下一个 H1 或 H2 标题。

I have a WORD document with a number of H1 headings. I'd like a macro that allows me to delete all the contents from a specific H1 heading until the next H1 heading - essentially deleting the H1 section. Similarly I might want to delete from a H2 heading until the next H1 or H2 heading.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长途伴 2024-08-04 23:23:46

您可以使用 oParagraph.Style 确定段落的样式(其中 oParagraph 是 Paragraph 对象)。 所以,你可以这样做:

Dim oStartHeadingParagraph As Paragraph
Set oStartHeadingParagraph = Selection.Paragraphs(1)

If oStartHeadingParagraph.Style <> "Heading 1" Then
    MsgBox "Please select the Heading 1 paragraph for the section you want to delete."
Else

    Dim oParagraph As Paragraph
    Set oParagraph = oStartHeadingParagraph

    Do While Not oStartHeadingParagraph.Next Is Nothing
        If oStartHeadingParagraph.Next.Style = "Heading 1" Then
            Exit Do
        Else
            oStartHeadingParagraph.Next.Range.Delete
        End If
    Loop

    oStartHeadingParagraph.Range.Delete

End If

You can determine the style of a paragraph using oParagraph.Style (where oParagraph is a Paragraph object). So, you could do something like:

Dim oStartHeadingParagraph As Paragraph
Set oStartHeadingParagraph = Selection.Paragraphs(1)

If oStartHeadingParagraph.Style <> "Heading 1" Then
    MsgBox "Please select the Heading 1 paragraph for the section you want to delete."
Else

    Dim oParagraph As Paragraph
    Set oParagraph = oStartHeadingParagraph

    Do While Not oStartHeadingParagraph.Next Is Nothing
        If oStartHeadingParagraph.Next.Style = "Heading 1" Then
            Exit Do
        Else
            oStartHeadingParagraph.Next.Range.Delete
        End If
    Loop

    oStartHeadingParagraph.Range.Delete

End If
臻嫒无言 2024-08-04 23:23:46

您不需要宏:在大纲视图中编辑文档。 导航到那里并仅选择标题级别 1,如下所示:

View > Outline 

接下来,选择级别:

Show Level > Level 1.  

仅删除不再希望保留的 H1 标题。 您可以拖动& 删除标题,然后是从属内容。

这是根据需要进行大规模编辑的绝佳视图。

You don't need a macro: edit the document in Outline view. Navigate there and select only headings level 1, as follows:

View > Outline 

Next, select the level:

Show Level > Level 1.  

Delete only the H1 headings you no longer want to keep. You can drag & drop headings, and the subordinate content will follow.

This is a great view for doing large-scale editing as you require.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文