Consulting

Results 1 to 2 of 2

Thread: Check completeness of form and generate a copy (.doc) without the content controls

  1. #1

    Check completeness of form and generate a copy (.doc) without the content controls

    I have a template, password protected. I wanted a macro that can do the following:

    I don’t want a macro button so I want this macro to run automatically when user attempt to save the file:


    1. Macro to ensure all content controls are completed
    2. if not all content controls are completed – ask user to a) complete or b) close file without saving a copy
    3. If all content controls are completed – Ask user if want to generate a confirm copy.

    1. If yes macro to do the following:

    • Hide Instruction Table (I have bookmarked this as “bmTable”)
    • remove all content control box, data in the content control box to remain
    • Generate a soft copy of a word document (not macro enabled) and open it and prompt user to save a copy of the newly generated word document.

    2. If No do the following:

    • Ask user if want to exit – Yes (exit), No (next step)
    • Ask user if want to save a copy of the document (macro enabled)


    However, I am stuck halfway and got confused with the code. I found the code below in the forum and wanted to make additions to it and got confused. This code cannot detect placeholder in the content control box and treat the content controls are completed and it just cannot close if controls are not completed.
    Please help me. This is the last step to my form after many many days of trying. Thanks a lot!

    Private Sub AutoClose()
    Dim CCtrl As ContentControl, Cancel As Boolean: Cancel = False
    With ActiveDocument
    For Each CCtrl In .ContentControls
    If CCtrl.ShowingPlaceholderText = True Then Cancel = True: CCtrl.Range.Select: Exit For
    Next
    If Cancel = True Then
    MsgBox "”
       ‘ .Saved = False
        SendKeys "{ESC}"
    End If
    End With
    End Sub

  2. #2
    VBAX Contributor
    Joined
    Jul 2020
    Location
    Sun Prairie
    Posts
    123
    Location
    1. You can use the Content Control properties when you create your template to remove a Content Control when it is edited. You do not need vba for that task.
    2. You should be using a template, not a document. The default behavior of a template is creation of a new document based on the template. To use a template via vba, you use Documents.Add.


    These are things built into the Word object model. You do not need to re-write them.

Posting Permissions

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