【问题标题】:Pulling value from drop down list, trouble due to form protection从下拉列表中提取值,由于表单保护而引起的麻烦
【发布时间】:2018-01-26 22:46:14
【问题描述】:

我有一个按钮、一个旧式下拉表单和一个表格。

当我按下按钮时,VBA 代码会从我的旧下拉表单中拉出当前选定的项目,并将其插入到我的表格中。

With ActiveDocument

    .Tables(15).Rows.Last.Cells(1).Range.InsertAfter .FormFields("DropDown2").Result

End With

但是,当我处于非保护模式时,下拉列表不会“下拉”。我需要用户能够从下拉表单中进行选择。

因此,我更改为保护模式以允许下拉列表正常运行。但是,当我在保护模式下运行宏时,我收到此错误:

This method or property is not available because the object refers to a protected area of a document.

我能做什么?我的方法是完全错误的,还是有解决办法?

这是对User selects item from drop down box, clicks button, and the selected item populates the last row of a table的跟进

【问题讨论】:

    标签: vba ms-word


    【解决方案1】:

    首先,您应该检查文档是否受到保护(听起来像是受保护)。然后暂时禁用保护,进行更改,重新启用保护。

    With ActiveDocument
        If .ProtectionType <> wdNoProtection Then .Unprotect
        .Tables(15).Rows.Last.Cells(1).Range.InsertAfter .FormFields("DropDown2").Result
        .Protect wdAllowOnlyFormFields
    End With
    

    因此,请继续保护您的文档以供下拉列表使用。此代码将处理其余部分。

    【讨论】:

    • 如果我想在它的末尾添加ActiveDocument.Tables(15).Rows.Add,这样我就可以在.InsertAfter之后在我的表格中添加一行,我应该在哪里添加它?是否需要在With条件内?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多