gpt4 book ai didi

vba - 如何使用 VBA 在 Outlook 约会中插入 Quick Parts Building Block?

转载 作者:行者123 更新时间:2023-12-05 05:22:09 27 4
gpt4 key购买 nike

我在 Microsoft Outlook 2016 中有一个名为“ session 目的 block ”的 QuickParts Building Block。我可以通过功能区导航来使用它,但我不知道如何编写 VBA(即宏)来执行相同的操作。

screenshot from Outlook

据我所知,Building Block 是名为“NormalEmail.dotm”的 Microsoft Word 模板的一部分,因此我假设我必须在我的代码中使用 Word VBA 库。

最佳答案

您将需要添加对 Word tlb 的引用或将所有 Word.* 变量更改为 Variant

Sub InsertBuildingBlock()
Dim oInspector As Inspector
Dim oDoc As Word.Document
Dim wordApp As Word.Application
Dim oTemplate As Word.Template
Dim oBuildingBlock As Word.BuildingBlock

''Or get the inspector some other way
Set oInspector = Application.ActiveInspector

If oInspector.EditorType = olEditorWord Then

''The property WordEditor is a Word.Document
Set oDoc = oInspector.WordEditor

''This inserts the firt building block in the first template
''This is based on a simple recording action in Word
Set wordApp = oDoc.Application
Set oTemplate = wordApp.templates(1)
Set oBuildingBlock = oTemplate.BuildingBlockEntries(1)

oBuildingBlock.Insert wordApp.Selection.Range, True
End If

End Sub

关于vba - 如何使用 VBA 在 Outlook 约会中插入 Quick Parts Building Block?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41289181/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com