【问题标题】:Set Word Content Control from Access从 Access 设置 Word 内容控制
【发布时间】:2016-10-24 19:18:04
【问题描述】:

我有一个用于文档的 word 模板。我想在 MS Access 的 word 文档中设置内容控件。我想出了如何在 Word 中设置项目,

ActiveDocument.ContentControls(14).Checked = True
activedocument.ContentControls(1).DropdownListEntries.Item(3)enter code here

但是当我尝试从 Access 执行此操作时,我无法弄清楚如何调用内容控件。

这是我在替换书签时使用的代码,我尝试将内容控件放入其中,但没有成功:

Set WordApp = GetObject(, "Word.Application")
WordApp.Visible = True
WordApp.WindowState = wdWindowStateMaximize
WordApp.Documents.Add Template:=strTemplateLocation, NewTemplate:=False

With WordApp.Selection

.GoTo what:=wdGoToBookmark, Name:="COMPANY"
.TypeText [fac]
'that works

Dim oCtrl As ContentControl
set oCtrl = .ContentControl(14)
oCtrl.Checked = True

然后我得到一个编译错误,指出“找不到方法或数据成员”。突出显示倒数第二行的“ContentControl”。

我已经很久没有使用代码了,所以如果有明显的问题,请原谅。

谢谢,

【问题讨论】:

    标签: vba ms-access ms-word


    【解决方案1】:

    玩了一会儿,找到了解决办法。

    添加:

    dim wDoc as Word.Document
    

    从 With 语句中删除 .Selection

    With WordApp
    

    在书签替换语句中添加了 .Selection

    .Selection.GoTo what:=wdGoToBookmark, Name:="COMPANY"
    .Selection.TypeText [fac]
    

    然后对于复选框:

    ActiveDocument.ContentControls(6).Checked = True
    

    现在工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多