Solved

Tally content control results (Word 2010)

Posted on 2014-01-16
5
513 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

785 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