Can I use Macro to add a live counter in Google Docs that tallies bullets by section?

130 views Asked by At

I have a long numbered list in Google docs with numerous sections (the number sequence spans across sections). I want to be able to track the number of list items within each section, ideally as a live counter added in parenthesis to the section header, that way it will show up in the auto-table of contents.

I don't know code (beyond some SQL and spreadsheet logic) but I saw someone's post on DataNumen's blog that uses Macro to count the bullets in the whole list. I'll post that code below, but I'm looking to overcome to obstacles to that. First, the output needs to be in the text, not a pop-up window. Second, the bullets should only be counted within each section, not the whole doc.

Here's a link to an example [Google Doc][1] (copy)

CODE from DataNumen.com:

    Sub GetNumberOfBullets()
   Dim objRange As Range
   Dim objParagraph As Paragraph
   Dim nNumber As Integer
 
   '  Initialization
   Set objRange = Selection.Range
   nNumber = 0
 
   For Each objParagraph In objRange.Paragraphs
   If objParagraph.Range.ListFormat.ListType = WdListType.wdListBullet Then
     nNumber = nNumber + 1
   End If
   Next objParagraph
 
   '  Pop up a message box to show the total number of bullets.
   MsgBox ("Bullet number:" & nNumber)
 End Sub
0

There are 0 answers