Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-05-2021, 04:01 PM
Guessed's Avatar
Guessed Guessed is offline Macro command to count checkboxes and provide metrics Windows 10 Macro command to count checkboxes and provide metrics Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,159
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, 17 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add / Sum checked Checkboxes labelled 1, 2, 3, etc. in Word Table - Need Macro? klearazkrystal Word VBA 7 03-31-2019 11:50 PM
Need Macro to select Checkbox after two boxes are checked in a series of checkboxes rsaini Word VBA 0 01-16-2018 11:57 AM
count selected checkboxes in each group a888 Word VBA 8 02-24-2015 04:44 AM
Ammunition count macro Owastell Excel Programming 3 07-03-2014 11:00 AM
Collecting Metrics in Project TimJimO Project 0 12-29-2010 12:12 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:39 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft