Solved

Tally content control results (Word 2010)

Posted on 2014-01-16
5
514 Views
Last Modified: 2014-01-17
Hi Folks!  Been a long time since I was here..... wow.  Guess I'm still #2 overall in Word!  Grandkids take all my time now :)

In any event, I'm a bit rusty and need to count the number of content controls in a Word document that contain a certain phrase.  There are two items in the dropdown: "Inside authorized area" and "Outside authorized area"  

This document may be used on a daily basis, and after the individual has completed the entry for the day, I would like it to tally and give a message box saying how many days he has been "Outside authorized area".  I guess a DOCVARIABLE at the bottom and a MsgBox pop up.

I've attached a document which I started naming the content controls only up through January.  Hope this makes sense.  If you have a better idea, please offer it!  Many thanks.
Location-Tracking-Calendar.docx
0
Comment
Question by:Joanne M. Orzech
  • 3
  • 2
5 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 39786816
Hi Joanne and how are the grandchildren - and your son and his wife? I still have a picture from 2007 of one (the first?) of the babies.

Here is some code. It creates or updates a document variable so you can put one or more DOCVARIABLE fields somewhere on the document to display the result.
Sub CountCCbyText()
    Dim CC As ContentControl
    Dim iCount As Integer
    Dim strText As String
    Dim docVar As Variable
    
    strText = "Outside authorized area"
    For Each CC In ActiveDocument.ContentControls
        If CC.Range.Text = strText Then
            iCount = iCount + 1
        End If
    Next CC
    
    For Each docVar In ActiveDocument.Variables
        If docVar.Name = "varOutSide" Then
            docVar.Value = iCount
            Exit Sub
        End If
    Next docVar
    
    If docVar Is Nothing Then
        Set docVar = ActiveDocument.Variables.Add("varOutSide", iCount)
    End If
    
    MsgBox "There are " & iCount & " instances of " & """" & strText & """"
End Sub

Open in new window

0
 
LVL 37

Author Comment

by:Joanne M. Orzech
ID: 39788334
Everyone is great Graham!  Thank you for asking.  My oldest granddaughter is going to be 8 and Anthony will be 3!  Such a blessing they are :)

Thanks much for the code.  I am under some time constraints on this project so will test this morning and let you know if I have further questions.  

I hope all is well with you.  I do have to get back into EE and answering some questions.  I miss it!    Warm regards.

Joanne
0
 
LVL 37

Author Comment

by:Joanne M. Orzech
ID: 39788348
omgosh!  This is EXACTLY what I needed.... thanks so much Graham.  You are the very best! :)
0
 
LVL 37

Author Closing Comment

by:Joanne M. Orzech
ID: 39788349
Quick and perfecto!
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39788458
Thank you Joanne. It was a real pleasure.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
My experience with Windows 10 over a one year period and suggestions for smooth operation
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question