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.