Macro

nparsons75

Well-known Member
Joined
Sep 23, 2013
Messages
1,256
Office Version
  1. 2016
This may be a strange place to ask this but I have it feeling it will be the same. I have a word template which I have created. It contains numerous content controls. I need a macro button that will clear the control content to enable me to start filling the form again. I have had so much success on here I thought I would give it a go. Thanks.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You could loop through all the formfields within the document resetting to a default value

Code:
    Dim FF As FormField
 
    For Each FF In ActiveDocument.FormFields
         Select Case FF.Type
             Case wdFieldFormTextInput
                 FF.Result = ""
             Case wdFieldFormDropDown
                 FF.DropDown.Value = 1
             Case Else
                 ' do nothing
         End Select
     Next
 
Upvote 0
You could loop through all the formfields within the document resetting to a default value
That's all very well, but:
I have a word template which I have created. It contains numerous content controls.
Content controls are not formfields.

nparsons75: Text, picture & date content controls are easily-enough cleared but, if you have checkbox content controls, what default do you want to set them to - checked or unchecked?
 
Upvote 0
yes I found this, the controls did not clear, I was to reply this morning.

the default for checkboxes would be unchecked.

thanks both of you fit the help. @macropod, would be fantastic if you could help show me how to do this.

thanks



That's all very well, but:

Content controls are not formfields.

nparsons75: Text, picture & date content controls are easily-enough cleared but, if you have checkbox content controls, what default do you want to set them to - checked or unchecked?
 
Upvote 0
Try:
Code:
Sub ClearAllContentControls()
Application.ScreenUpdating = False
Dim CCtrl As ContentControl
For Each CCtrl In ActiveDocument.ContentControls
  On Error Resume Next
  With CCtrl
    Select Case .Type
     Case wdContentControlCheckBox: .Checked = False
     Case wdContentControlComboBox: .DropdownListEntries(1).Select
     Case wdContentControlDropdownList: .DropdownListEntries(1).Select
     Case wdContentControlPicture: If .ShowingPlaceholderText = False Then .Range.InlineShapes(1).Delete
     Case Else: .Range.Text = ""
    End Select
  End With
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
My bad, Macropod! Missed that one. Sometimes the quickest way to get the right answer is to post the wrong one.
 
Upvote 0

Forum statistics

Threads
1,226,116
Messages
6,189,054
Members
453,523
Latest member
Don Quixote

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top