【问题标题】:Word VBA ContentControl error (appears locked)Word VBA ContentControl 错误(显示为锁定)
【发布时间】:2019-05-05 14:37:35
【问题描述】:

我正在尝试基于另一个控件以编程方式更新某些内容控件的文本。我收到以下错误:

“运行时错误 6124。您不能编辑此选择,因为它受到保护”。

到目前为止,这是我的代码:

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)

Select Case ContentControl.Title
    Case "Party"
        Call CascadeParty(ContentControl)
End Select

End Sub



Sub CascadeParty(ByVal cControl As ContentControl)

Dim con As ContentControl

For Each con In ActiveDocument.ContentControls
    If con.Title = "Party" Then
        con.Range.Text = cControl.Range.Text ' ERROR HERE
    End If
Next con

End Sub

我也尝试过传递字符串而不是控件,同样的问题。 on this similar post 的答案都没有帮助。该文档不受任何保护,并且没有任何内容控件被锁定。

有什么想法吗?谢谢。

更新:我已经在一个新的干净文档中尝试了我的代码,它工作正常,所以这是我收到的文档的一些内容。同样,没有任何东西受到保护,所以我仍然不知所措。

【问题讨论】:

    标签: vba ms-word


    【解决方案1】:

    Protected”可能意味着ContentControl被设置为“Cannot Edit”。就在你说“con.range.text = ...”之前,输入一行“con.LockContents = False”。在那之后,您可能想将con.LockContents 设置回True

    【讨论】:

      猜你喜欢
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-03
      • 1970-01-01
      • 2019-01-30
      相关资源
      最近更新 更多