Gen Tan
Gen Tan

Reputation: 918

Pulling value from drop down list, trouble due to form protection

I have a button, a legacy drop down form, and a table.

When I press my button, VBA code pulls the currently selected item from my legacy drop down form, and inserts it into my table.

With ActiveDocument

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

End With

However, the drop down list does not "drop down" when I am in non-protected mode. I need users to be able to select from the drop down form.

So, I changed to protected-mode to allow the drop down list to function normally. However, when I run the macro in protected mode, I receive this error:

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

What can I do? Is my approach totally wrong, or is there a fix for this?

This is a follow up to User selects item from drop down box, clicks button, and the selected item populates the last row of a table

Upvotes: 0

Views: 69

Answers (1)

K.Dᴀᴠɪs
K.Dᴀᴠɪs

Reputation: 10139

First, you should check if the document is protected (which it sounds like it will be). Then temporarily disable the protection, make your changes, the re-enable protection.

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

So go ahead and keep your document protected for your drop down. This code will take care of the rest.

Upvotes: 1

Related Questions