Macro to count the instances of a quick part template in a doc

A

ash

I am trying to build a macro which will scan a document for a particular
building block (which is a template saved as quick part) and count the total
number of instances. For ex. Assuming there is a quick part template which is
a table for each use case, the user inserts many of these quick parts in the
document..one for each usecase. Finally the New macro has to scan the
document and show the count of these the quick part inserts/use cases. (This
will be extended in future to get more information).

Questions :
1. where are the document specific building blocks stored (specifically the
templates in Quickparts gallery shown in the building block organizer )

2. once the building block is instered, will there be any specific tag which
we can use to know that the inserted info is from quick parts gallery or is a
building block.

3. (I saved the word doc as a .zip and unzipped it. Is there any specific
file in this archive that stores this info)
 
G

Graham Mayor

ash said:
I am trying to build a macro which will scan a document for a
particular building block (which is a template saved as quick part)
and count the total number of instances. For ex. Assuming there is a
quick part template which is a table for each use case, the user
inserts many of these quick parts in the document..one for each
usecase. Finally the New macro has to scan the document and show the
count of these the quick part inserts/use cases. (This will be
extended in future to get more information).

I suppose that if you inserted the quickpart using a macro you could add a
counter to the insertion macro.
Maybe something like

Sub InsertBBName()
Dim oVars As Variables
Dim Count As Long
Set oVars = ActiveDocument.Variables
'if the variable doesn't exist go to the error routine
On Error GoTo NoVar
'read the count from the variable
Count = oVars("varCount").Value
'insert the building block
NormalTemplate.BuildingBlockEntries("BBName").Insert Where:=Selection. _
Range, RichText:=True
'increment the counter
oVars("varCount").Value = Count + 1
Exit Sub
NoVar:
'create the variable and set the initial value to 0
If Err.Number = 5825 Then oVars("varCount").Value = "0"
'go back to the macro
Resume
End Sub

which would put the number of insertions in a docvariable varCount.
Questions :
1. where are the document specific building blocks stored
(specifically the templates in Quickparts gallery shown in the
building block organizer )

The building blocks organiser template column indicates where a particular
building block is stored.
2. once the building block is instered, will there be any specific
tag which we can use to know that the inserted info is from quick
parts gallery or is a building block.

No - if you insert a building block it simply becomes part of the text of
the document.
3. (I saved the word doc as a .zip and unzipped it. Is there any
specific file in this archive that stores this info)

No. Word has no ZIP compatibility whatsoever.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

ash

Thanks a lot Graham for the suggestion and the answers. I will proceed in the
direction you mentioned.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top