The problem is that xFileName.SelectContentControlsByTag("q_179").Item(1)
returns a ContentControl object, and a ContentControl object is not a number that can be compared in an expression such as Counter < Total
In this case the way to get the number is to get the ContentControl's Range.Text and convert it to a number (and you might also need to verify that it is a number).
e.g.assuming you know the number is an Integer you could use
Dim ccValue As Integer
ccValue = CInt(xFileName.SelectContentControlsByTag("q_179").Item(1).Range.Text)
.
.
Loop While Counter < ccValue
Because VBA makes a number of assumptions, if you know the value is Numeric you could probably 'get away' with something more like
Dim ccValue As Integer
ccValue = xFileName.SelectContentControlsByTag("q_179").Item(1).Range
.
.
Loop While Counter < ccValue
You may be wondering why it's valid to use .Range
rather than .Range.Text
but not OK to use (in effect) objCC.Range
. That's because .Text is the "Default Member" of the Range object, so when you use .Range without specifying a member, VBA returns the value of the default member. But I think a lot of people would say it's not a very good practice and it's better to specify the member.
To explore Default Members in more detail, open the View->Object Broswer window in Word's VB Editor, and search for the object/class, e.g. Range. Select it, and the relevant Class should be selected in the list of Classes (to the bottom left, probably). Then look through the list of members of the class. If there is a Default Member, its name should be bolded.
You may also be wondering why it's valid to omit the CInt(). It's because VB can "coerce" a string type into being a numeric type, when it contains a number at any rate. But it's usually better to specify an explicit conversion (especially because the result of a conversion can depend on Regional locale settings in e.g. Windows).