PDA

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



elaineada75
04-29-2022, 05:53 AM
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:


[*=2]Hide Instruction Table (I have bookmarked this as “bmTable”)
[*=2]remove all content control box, data in the content control box to remain
[*=2]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:


[*=2]Ask user if want to exit – Yes (exit), No (next step)
[*=2]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

Chas Kenyon
04-29-2022, 10:58 AM
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.
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.