在插入构建块之前定位光标,同时避免之后分页

发布于 2025-01-09 03:03:21 字数 538 浏览 0 评论 0原文

我有一个全页的 Building Block,通过 Building Blocks Organizer 保存为名称:“aWaiver”,在我的自定义类别中:“Quick Parts”库中的“Waivers”,其中 Building Block 属性:“在其自己的页面上插入内容”。

两个问题: (1) 我似乎无法找到正确的“Selected.Range”VBA 代码来用于定位到我想要插入 aWaiver 构建块的当前(最后或唯一)页面的底部。 (2) 当我手动找到文档底部并插入 aWaiver 时,它确实开始了自己的页面,但随后插入了另一个空白页。

这是我根据录制的宏修改的 vba 代码,尽管存在上述问题,但它似乎可以工作。

        "C:\Users\Brian\AppData\Roaming\Microsoft\Templates\Normal.dotm"). _
        BuildingBlockEntries("aWaiver").Insert Where:=Selection.Range, _
        RichText:=True```

I have a full-page Building Block I saved through the Building Blocks Organizer as name: "aWaiver" in my custom category: "Waivers" in the "Quick Parts" Gallery with Building Block Property: "insert content on its own page".

Two issues:
(1) I cannot seem to discover the proper "Selected.Range" VBA code to use to locate to the bottom of the current (last or only) page where I want to insert my aWaiver building block.
(2) When I manually locate to the bottom of my document and insert the aWaiver, it does begin its own page, but then inserts another following blank page.

Here is vba code I modified from the macro I recorded that seems to work albeit with the above issues.

        "C:\Users\Brian\AppData\Roaming\Microsoft\Templates\Normal.dotm"). _
        BuildingBlockEntries("aWaiver").Insert Where:=Selection.Range, _
        RichText:=True```

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

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

发布评论

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

评论(2

那小子欠揍 2025-01-16 03:03:22
  1. 编写 VBA 时,Selection 对象仅在不可避免的极少数情况下使用。要在文档末尾添加您的 Building Block,您可以使用 Where:=Document.Characters.Last
  2. Building Block 应存储在您的文档模板中,而不是 Normal.dotm,否则您将无法能够将其分发给其他用户。
  3. 空白页面的问题是由您包含在 Building Block 中的内容造成的。
  1. When writing VBA the Selection object is only used in exceptionally rare circumstances when it is unavoidable. To add your Building Block at the end of the document you can use Where:=Document.Characters.Last
  2. The Building Block should be stored in your document template, not Normal.dotm, otherwise you will not be able to distribute it to other users.
  3. The issues with the blank page are a result of the content that you have included in the Building Block.
相守太难 2025-01-16 03:03:22

鉴于我获得单词读写能力的建议,我不愿意发帖。但这篇文章确实出现在谷歌搜索中各种关键词的结果中。因此,我将分享我的解决方案,因为我知道它缺乏最佳实践。

在原型文档最后一段的末尾,我添加了一个 bkPageBreakHere 书签。然后,我将快速零件库中的选择另存为新类别 WaiversaPartialWaiver,并带有选项 仅插入内容(结果是 将内容作为其自己的页面插入 在之后而不是之前进行分页)

转向 VBA 代码,我发现 Building Blocks 不会自动随我的模块一起加载。因此,我在文档中输入:

Private Sub Document_New()
'load Building Blocks
    Application.Templates.LoadBuildingBlocks
'Present Waiver Form
    formCombined.Show

End Sub

Private Sub Document_Open()
'load Building Blocks
    Application.Templates.LoadBuildingBlocks
'Present Waiver Form
    formCombined.Show
End Sub

最后,在我的表格中:

Private Sub CommandNext_Click()

                 ...
   Selection.GoTo what:=wdGoToBookmark, Name:="bkPageBreakHere"  'Position cursor
   Selection.InsertBreak Type:=wdPageBreak                       'Start new page                                           
'load next document
    Application.Templates( _
        "C:\Users\" & Environ("username") & "\AppData\Roaming\Microsoft\Document Building Blocks\1033\16\Building Blocks.dotx" _
        ).BuildingBlockEntries("aPartialWaiver").Insert Where:=Selection.range, _
        RichText:=True
                 ...

问题仍然存在。 (1) 尽管如此,我在最后一个合法页面之后仍然得到一个空白页面。 (不,我不会在最后一页上执行上述代码部分。) (2) 从模板调用文档时,我收到“安全警告宏已被禁用”。

但总而言之,客户很满意。我将继续我的努力寻找解决方案。欢迎任何想法,但不是预期的。

I’m reluctant to post given the recommendation that I gain Word literacy. But this post does appear in results for various key words in a Google Search. So, I will share my solution knowing that it lacks best practices.

At the end of my last paragraph in my prototype document I added a bkPageBreakHere bookmark. I then saved the selection in the Quick Parts gallery as a new Category Waivers as aPartialWaiver with Option insert content only (turns out that insert content as its own page does the page break after, not before)

Turning to the VBA Code, I found that Building Blocks did not automatically load with my module. So into the document I entered:

Private Sub Document_New()
'load Building Blocks
    Application.Templates.LoadBuildingBlocks
'Present Waiver Form
    formCombined.Show

End Sub

Private Sub Document_Open()
'load Building Blocks
    Application.Templates.LoadBuildingBlocks
'Present Waiver Form
    formCombined.Show
End Sub

Finally, in my form:

Private Sub CommandNext_Click()

                 ...
   Selection.GoTo what:=wdGoToBookmark, Name:="bkPageBreakHere"  'Position cursor
   Selection.InsertBreak Type:=wdPageBreak                       'Start new page                                           
'load next document
    Application.Templates( _
        "C:\Users\" & Environ("username") & "\AppData\Roaming\Microsoft\Document Building Blocks\1033\16\Building Blocks.dotx" _
        ).BuildingBlockEntries("aPartialWaiver").Insert Where:=Selection.range, _
        RichText:=True
                 ...

Issues remain. (1) Despite everything, I still get an empty page after my last legitimate one. (No, I do NOT execute the above code section on my last page.) (2) I get the “Security warning Macros have been disabled” when invoking the document from a template.

But all in all, the client is satisfied. I’ll continue my flailing to find a solution. Any thoughts welcome but not expected.

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