Solved

Tally content control results (Word 2010)

Posted on 2014-01-16
5
516 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

695 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