Counting how many times a template is accessed

L

Lee Kiwiflame

Is there a way to see how many times each of my templates is accessed by
people? I need to know what templates are being used and which aren't.

I have approximately 190 templates and need to keep a count for each
template over a month's period.
 
D

Doug Robbins - Word MVP

If you have the following code in an AutoNew macro in each template, where
you replace [TemplateName] with the name of the template, each time that a
new document is created from the template, the number of times that it has
been used will be written to the file TemplateUsage.

Dim Count As Long
Count = System.PrivateProfileString("DriveName:\TemplateUsage.txt",
"[TemplateName]", "Count")
If Count = "" Then
Count = 0
End If
System.PrivateProfileString("DriveName:\TemplateUsage.txt",
"[TemplateName]", "Count") = Count + 1

You will need to make sure that the location for the TemplateUsage.txt file
is one for which each user has write access.

The above will record all instances of the template usage, whether or not
the user proceeds to actually complete the creation of the document. If you
want to be a bit more precise and get the actual number of documents created
and saved from each template, then use the following instead:

In the AutoNew Macro, use:

Dim varsaved as Boolean
varsaved = False
With ActiveDocument
.Variables("varTemplateName").Value = "[TemplateName]"
.Variables("varSaved").Value = varsaved
EndWith

In a macros named FileSaveAs and FileSave, use

Dim varsaved as Boolean
Dim Count as Long

With ActiveDocument
varsaved = .Variables("varSaved").Value
If varsaved = False Then
varsaved = True
.Variables("varSaved").Value = varsaved
Count = System.PrivateProfileString("DriveName:\TemplateUsage.txt",
varTemplateName, "Count")
If Count = "" Then
Count = 0
End If
System.PrivateProfileString("DriveName:\TemplateUsage.txt",
varTemplateName, "Count") = Count + 1
End If
.Save
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
L

Lee Kiwiflame

I have tried both lots of code in a blank template and I keep getting an
error message: Run Time error "13" Type Mismatch.

I have tried to save it to different drive locations, I have also tried with
TemplateUsage.txt already created in the location and without it.

Any ideas as to why this might happen??

Doug Robbins - Word MVP said:
If you have the following code in an AutoNew macro in each template, where
you replace [TemplateName] with the name of the template, each time that a
new document is created from the template, the number of times that it has
been used will be written to the file TemplateUsage.

Dim Count As Long
Count = System.PrivateProfileString("DriveName:\TemplateUsage.txt",
"[TemplateName]", "Count")
If Count = "" Then
Count = 0
End If
System.PrivateProfileString("DriveName:\TemplateUsage.txt",
"[TemplateName]", "Count") = Count + 1

You will need to make sure that the location for the TemplateUsage.txt file
is one for which each user has write access.

The above will record all instances of the template usage, whether or not
the user proceeds to actually complete the creation of the document. If you
want to be a bit more precise and get the actual number of documents created
and saved from each template, then use the following instead:

In the AutoNew Macro, use:

Dim varsaved as Boolean
varsaved = False
With ActiveDocument
.Variables("varTemplateName").Value = "[TemplateName]"
.Variables("varSaved").Value = varsaved
EndWith

In a macros named FileSaveAs and FileSave, use

Dim varsaved as Boolean
Dim Count as Long

With ActiveDocument
varsaved = .Variables("varSaved").Value
If varsaved = False Then
varsaved = True
.Variables("varSaved").Value = varsaved
Count = System.PrivateProfileString("DriveName:\TemplateUsage.txt",
varTemplateName, "Count")
If Count = "" Then
Count = 0
End If
System.PrivateProfileString("DriveName:\TemplateUsage.txt",
varTemplateName, "Count") = Count + 1
End If
.Save
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Lee Kiwiflame said:
Is there a way to see how many times each of my templates is accessed by
people? I need to know what templates are being used and which aren't.

I have approximately 190 templates and need to keep a count for each
template over a month's period.
 
D

Doug Robbins - Word MVP

Change the:

Dim Count as Long

to:

Dim Count As Variant

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Lee Kiwiflame said:
I have tried both lots of code in a blank template and I keep getting an
error message: Run Time error "13" Type Mismatch.

I have tried to save it to different drive locations, I have also tried
with
TemplateUsage.txt already created in the location and without it.

Any ideas as to why this might happen??

Doug Robbins - Word MVP said:
If you have the following code in an AutoNew macro in each template,
where
you replace [TemplateName] with the name of the template, each time that
a
new document is created from the template, the number of times that it
has
been used will be written to the file TemplateUsage.

Dim Count As Long
Count = System.PrivateProfileString("DriveName:\TemplateUsage.txt",
"[TemplateName]", "Count")
If Count = "" Then
Count = 0
End If
System.PrivateProfileString("DriveName:\TemplateUsage.txt",
"[TemplateName]", "Count") = Count + 1

You will need to make sure that the location for the TemplateUsage.txt
file
is one for which each user has write access.

The above will record all instances of the template usage, whether or not
the user proceeds to actually complete the creation of the document. If
you
want to be a bit more precise and get the actual number of documents
created
and saved from each template, then use the following instead:

In the AutoNew Macro, use:

Dim varsaved as Boolean
varsaved = False
With ActiveDocument
.Variables("varTemplateName").Value = "[TemplateName]"
.Variables("varSaved").Value = varsaved
EndWith

In a macros named FileSaveAs and FileSave, use

Dim varsaved as Boolean
Dim Count as Long

With ActiveDocument
varsaved = .Variables("varSaved").Value
If varsaved = False Then
varsaved = True
.Variables("varSaved").Value = varsaved
Count =
System.PrivateProfileString("DriveName:\TemplateUsage.txt",
varTemplateName, "Count")
If Count = "" Then
Count = 0
End If
System.PrivateProfileString("DriveName:\TemplateUsage.txt",
varTemplateName, "Count") = Count + 1
End If
.Save
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Lee Kiwiflame said:
Is there a way to see how many times each of my templates is accessed
by
people? I need to know what templates are being used and which aren't.

I have approximately 190 templates and need to keep a count for each
template over a month's period.
 

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