problem with non-existing templates

J

jarod1701

Hi everyone,

I have a huge problem with a bunch of Word documents. They're all based
on a template which does no longer exist. Due to this it takes Word
about half a minute to open one of them. I need to remove this link
from the files.
I know I can programmatically change the linked template back to
normal.dot with AttachedTemplate but the problem is that I would have
to open every single document using the Documents.Open method which
again takes Word quite some time as mentioned above.
As I'm a novice to VBA I wonder if there is any way to tell Word's COM
object not to look for the non-existing template.

I've already tried using Microsoft's dsofile.dll but it seems like it's
not capable of WRITING the template-attribute.

The only solution I can see right now is to disable LAN access on my
machine while converting the files which I don't consider to be a
proper solution for the problem ;-)

Hope anyone of you can help me with this.

Thanks in advance.
 
J

Jean-Guy Marcil

(e-mail address removed) was telling us:
(e-mail address removed) nous racontait que :
Hi everyone,

I have a huge problem with a bunch of Word documents. They're all
based on a template which does no longer exist. Due to this it takes
Word about half a minute to open one of them. I need to remove this
link from the files.
I know I can programmatically change the linked template back to
normal.dot with AttachedTemplate but the problem is that I would have
to open every single document using the Documents.Open method which
again takes Word quite some time as mentioned above.
As I'm a novice to VBA I wonder if there is any way to tell Word's COM
object not to look for the non-existing template.

I've already tried using Microsoft's dsofile.dll but it seems like
it's not capable of WRITING the template-attribute.

The only solution I can see right now is to disable LAN access on my
machine while converting the files which I don't consider to be a
proper solution for the problem ;-)

Hope anyone of you can help me with this.

Thanks in advance.

You could create a temporary *.dot with the actual name in the actual
location your documents are expecting to find the template; then run the
macro to change the AttachedTemplate. At least, in this manner documents
will open normally and the process may run fairly fast.

Use the code at:
http://word.mvps.org/FAQs/MacrosVBA/BatchFR.htm
to set up the batch process, but change the Find/Replace code with he code
to change the attached template.


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
T

Tony Jollans

You could also include in it a document_open event which automatically
changed the attached template so that it would eventually fall into misuse
without any further action on your part.
 
J

jarod1701

First of all, thanks to both of you.

@Jean-Guy:
I already thought about that. The problem is that the application I'm
supposed to write will be used sporadically by different people. This
makes it quite difficult to "rebuild" the directory structure
everytime.

@Tony:
As I already mentioned I'm quite new to VBA. Wouldn't the Document_Open
event only fire when it's alread "too late" ?
Anyway, I'll try that of course.
 
J

Jean-Guy Marcil

(e-mail address removed) was telling us:
(e-mail address removed) nous racontait que :
First of all, thanks to both of you.

@Jean-Guy:
I already thought about that. The problem is that the application I'm
supposed to write will be used sporadically by different people. This
makes it quite difficult to "rebuild" the directory structure
every time.


In that case, if you provide a dummy template and put it in your users'
"User Templates" folder, Word will find it (Word always find a document's
template in the "User Templates," "Workgroup Templates" and "Default
Template" folders. Knowing this, it is easy to distribute templates and not
worry about exact paths as long as users use one of those three folders) and
I believe it will be faster than trying to look for a non-existing template
in a non-existing path.

I do not have a network with which to try it, but it would not take you long
to test it.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

jarod1701

I just tried that. I put a dummy template in my user templates folder
and renamed it to the corresponding name. The only difference is that
Word now automatically applies the new path to the document's
AttachedTemplate property but it still takes it about 30 seconds to
open the doc. It was a cool idea nonetheless.
 
J

Jean-Guy Marcil

(e-mail address removed) was telling us:
(e-mail address removed) nous racontait que :
I just tried that. I put a dummy template in my user templates folder
and renamed it to the corresponding name. The only difference is that
Word now automatically applies the new path to the document's
AttachedTemplate property but it still takes it about 30 seconds to
open the doc. It was a cool idea nonetheless.

This means Word first tries to resolve the current AttachedTemplate Path.

Unless the Path is available, I don't know how you can force Word to ignore
that path...

See the discussion at:
http://tinyurl.com/8utpd
for some other explanations and or ideas.


By the way, I do not think you ever mentioned your version of Word...

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
T

Tony Jollans

Word looks first in the same directory as the document - I can't remember
all the rest of the search order off the top of my head - because that
allows you to package up a document and its template to, say, e-mail to
someone else and for them to have the correct template.

So create a template (with the right name) in the folder with your docs -
and add something like this to its ThisDocument module

Private Sub Document_Open()
If ActiveDocument.Type = wdTypeDocument Then _
ActiveDocument.AttachedTemplate = NormalTemplate
End Sub
 
J

Jean-Guy Marcil

Tony Jollans was telling us:
Tony Jollans nous racontait que :
Word looks first in the same directory as the document - I can't
remember all the rest of the search order off the top of my head -
because that allows you to package up a document and its template to,
say, e-mail to someone else and for them to have the correct template.

I do not remember the search order as well, especially since it seems to
change slightly according to the version.

But, I always thought that the first place Word looked was the path
associated with the AttachedTemplate, if that fails, then comes the local
folder, then User, Workgroup, Default, etc.

This means that the 30 second delay will still be there, no?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
T

Tony Jollans

I just ran a quick test in 2003 to confirm -

Document in Folder A based on Template in Folder B
Copied Template to Folder A and also to User Templates Folder
Opened document and it used the local template (and successfully changed the
attached template to normal)
Saved and re-opened document and it no longer opened any copy of the
original template.

(All on local computer so can't say for sure it's not looking for something
else but I'm pretty sure it isn't)
 
C

Charles Kenyon

You might also want to put something in for when a user creates a new
document based on the dummy template, such as creating a new document based
on normal.dot instead.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
J

jarod1701

first of all thanks to all of you,

I'm afraid there is no really "nice" way to solve my problem.
Shame over Microsoft for this really annoying bug :)
 
T

Tony Jollans

Microsoft are far from perfect but this could hardly be called a bug! You
(perhaps not you personally, but your company) have deleted a template (or
the server it was on). Word looks for what it has been told to use and when
it can't find it, uses an alternative so that you can still work with your
document - seems a pretty good compromise to me. I'll grant it can be slow
doing this but that isn't under the control of Word - it's the network.

Have you tried my suggestion of putting a dummy template in the same
directory as the documents? Did it not work - or is there some reason that
you think it won't work for you?
 
J

jarod1701

Hi Tony,

It's annoying that one cannot remove the link to the template
programmatically WITHOUT openig the document first.

Your suggestion concerning the dummy template didn't work for me.
I think that is because Word first tries to find the original template
which non longer exists and after that looks for it in the doc's parent
folder.
 
T

Tony Jollans

I'm sorry it doesn't work. I've always understood that the first place Word
looks for templates is in the folder with the document and it has always
done that for me. Maybe there's an option somewhere that I've always got
switched on somehow, or maybe there's something else causing your problem.

I do understand your frustration and I know you have said you don't consider
it a proper solution, but logging off from the network while you run a batch
process would be another way of doing what you want.
 
C

Charles Kenyon

Note. The dummy template needs to have the same name as the original
template.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
J

jarod1701

After struggling with a few other approaches I solved my problem the
"simple" way:
I added the server formerly holding the templates to my local hosts
file using an IP address of an existing server. Word can now "reach"
the server and opens the documents within a second.
 

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