我在Microsoft Outlook 2016中有一个名为"会议用途块的QuickParts Building Block。"我可以通过导航功能使用它,但我无法弄清楚如何编写VBA,即宏,来做同样的事情。
据我所知,Building Block是名为" NormalEmail.dotm"的Microsoft Word模板的一部分,所以我假设我必须在我的代码中使用Word VBA库。
答案 0 :(得分:0)
您需要添加对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