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:
- Macro to ensure all content controls are completed
- if not all content controls are completed – ask user to a) complete or b) close file without saving a copy
- 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