How do I change a word template to a document?

A

Anjou blanc

A long time ago I left a team with a template file with lots of useful macros
and tools. Since then I've given them updates along the way. Now, we find
that there are lots of documents that have been created by people OPENING the
template (instead of using File->New) and then forcing Word to save the files
at .doc (i.e. they look like documents but they are still templates). There
are over 10,000 files (good and bad) stored in a hierarchical folder set.
Obviously I can get a list of all fo these documents by doing something like
'dir "*.doc" /s/b >list.txt', but once I've done that, what I'd like to do is:
- get a list of the files which have been incorrectly created as templates
- purge the old versions of the macros from those incorrectly saved files
- convert the bad files to proper documents based on the current version of
that template file
 
H

Howard Kaikow

A template cannot be saved as a document.

You could create a document based on the templates contents and then delete
the template.
 
A

Alex Ivanov

Howard,
It's not quite correct. Though most likely the vast majority of OP's
problematic documents are not templates any longer, some still may be. If
you open a template as a document and "Save As" a template, while Word will
try to give the file a dot extension, it's still possible to overwrite it,
for example enclosing the file name in quotes or giving the saved file a doc
extension from Windows Explorer. And there are plenty of smart fools that
will discover how to do the "impossible" things.

Anjou,
You may check the document's AttachedTemplate property. If it is the same as
the Name property (or simply ends with .doc), then it is a renamed template.

You can get rid of the code modules enumerating VBComponents. In Word 2k or
later you would need to enable access to code from the Tools/Macro/Security
menu to make it work.
Don't put the code into the "ActiveDocument" or it may happily delete itself
before anything else.

Sub RemoveCode()
Dim doc As Document
Dim i As Integer
Set doc = ActiveDocument
With doc.VBProject.VBComponents
For i = 2 To .Count 'can't delete 1 - Word's own stuff
.Remove .Item(i)
Next
End With
End Sub
 
H

Howard Kaikow

--
http://www.standards.com/; See Howard Kaikow's web site.
Alex Ivanov said:
Howard,
It's not quite correct. Though most likely the vast majority of OP's
problematic documents are not templates any longer, some still may be. If
you open a template as a document and "Save As" a template, while Word will
try to give the file a dot extension, it's still possible to overwrite it,
for example enclosing the file name in quotes or giving the saved file a doc
extension from Windows Explorer. And there are plenty of smart fools that
will discover how to do the "impossible" things.

Yes, but the critter still contains the macros, but loses the autotext..
Word 2003 warns about losing the autotext.

The file extension is not relevant.
 

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