Consulting

Results 1 to 6 of 6

Thread: Cant write into FormFields after apply ActiveDocument.Prtotect wdAllowOnlyFormFields

  1. #1
    VBAX Newbie
    Joined
    May 2019
    Posts
    3
    Location

    Cant write into FormFields after apply ActiveDocument.Prtotect wdAllowOnlyFormFields

    Hi

    I created a word file from nomal dot, adding a RichText ContentControl (with Default Properties) and a Command Button with following Code:


    Private Sub CommandButton1_Click()
    
    If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect
    Application.ActiveDocument.Protect wdAllowOnlyFormFields, Password:=""
    End Sub

    When click on the command button, it is not possible, to write into the RichText ContentControl-Form Field.


    When closing and opening the word file, the FormField gets editable again. Any idea, what goes wrong?


    PS: I reduced the problem to a minimal example. The real workflow is: Start with a protected word file, which contains a table. The word file contains a button which is linked to a macro to add a new row to the table (i.e. unprotect docuement, add row, protect document again) to insert then new information into the formfields.



    PS2: I use Microsoft Office Professional Plus 2010
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    A RichText Content Control is not a Formfield. Since your document contains no code for updating the content control, it's impossible to know what the cause of your problem is.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Newbie
    Joined
    May 2019
    Posts
    3
    Location
    Thank you for your quick answer, I see, that I mixed up ControlContents and FormFields.



    Thus, I have to ask my question in a different way: I want to add in a protected document a ControlContent with a macro, so that i can put some text in the ControlContent afterwards. The code of the macro would be:

    If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect
    Set objCC = ActiveDocument.ContentControls.Add(wdContentControlRichText)
    objCC.Title = "Comments"
    objCC.SetPlaceholderText , , "Comments"
    Application.ActiveDocument.Protect wdAllowOnlyFormFields, Password:=""
    Obviously this does not work. Thus, the question is now, can I protect the word file with vba in such a way, that the user can put text into, e.g. RichText-ControlContent some text?

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Why would you be adding the content control with code, rather than having one already in position?
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    VBAX Newbie
    Joined
    May 2019
    Posts
    3
    Location
    The macro adds a new row to an existing table. The content of the new row ist a Dropdown CC, datepicker CC, and finalliy I Need an object for free text Input. Since the number of rows cannot be predected, it must be possibe to add them at "runtime".

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •