Solved

Tally content control results (Word 2010)

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This collection of functions covers all the normal rounding methods of just about any numeric value.
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now