View Single Post
 
Old 08-05-2021, 04:01 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,994
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I think you should be using Content Controls for the checkboxes and the reporting fields.

This macro goes into the ThisDocument module
Code:
Private Sub Document_ContentControlOnExit(ByVal thisCC As ContentControl, Cancel As Boolean)
  Dim aCC As ContentControl, iTotal As Integer, iChecked As Integer, dPercent As Double
  If thisCC.Type = wdContentControlCheckBox Then
    iTotal = ActiveDocument.SelectContentControlsByTag("Check").Count
    For Each aCC In ActiveDocument.SelectContentControlsByTag("Check")
      If aCC.Checked Then iChecked = iChecked + 1
    Next aCC
    ActiveDocument.SelectContentControlsByTitle("Number Checked")(1).Range.Text = iChecked
    ActiveDocument.SelectContentControlsByTitle("Number Total")(1).Range.Text = iTotal
    ActiveDocument.SelectContentControlsByTitle("Percentage Checked")(1).Range.Text = Format(iChecked / iTotal, "0%")
  End If
End Sub
Have a look at the attached document as a demo. Check out the properties for each Content Control as they are important for the macro to run correctly.
Attached Files
File Type: docm Summary.docm (31.3 KB, 12 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote