0

我正在写一个提案,其中用户可以从构建块列表中选择所需的时间表长度,这样他们就不必输入整个段落。

构建基块选项屏幕截图

在此处输入图像描述

有没有办法可以更改使用 vba 代码选择的选项?

到目前为止,这是我在用户表单中使用组合框所尝试的:

Option Explicit

Private Sub CommandButton1_Click()

   If ComboBox1.Value = "Based on when drawings can be approved" Then

       Application.Templates( _
       "U:\Documents\2 Estimating Rotation\Repair Template\Repair Proposal 
       Template Rev1.dotm" _
       ).BuildingBlockEntries("Option 2").Insert Where:=Selection.Range, _
       RichText:=True

   End If

End Sub

Private Sub UserForm_Activate()

   'Schedule Options
   Me.ComboBox1.Clear
   Me.ComboBox1.AddItem "Based on when drawings can be approved"

End Sub

有没有办法更改“Selection.Range”以选择所需的“积木库内容控件”下拉菜单?目前,所有代码所做的都是在光标位置插入我存储在“选项 2”中的文本。

让我知道是否需要进一步澄清。

4

1 回答 1

0

不,没有从 Building Block 内容控件中选择条目的规定。您所能做的就是将所需的构建块条目插入到内容控件中。这不一定是Selection.Range,它可以是内容控件的Range。内容控件不关心插入的内容是否来自列表 - 内容控件将接受任何内容。

假设这是文档中的第一个内容控件,例如:

Dim cc As Word.ContentControl
Dim tmpl As Word.Template

Set cc = ActiveDocument.Contentcontrols(1)
Set tmpl = Templates("U:\Documents\2 Estimating Rotation\Repair Template\Repair Proposal Template Rev1.dotm")
tmpl.BuildingBlockEntries("Option 2").Insert cc.Range, True
于 2019-08-27T10:31:55.787 回答