Henry/Graham,
I think I understand the source of the problem, which may help you to find a
solution - altho I don't have one myself as I'm not a C# programmer. Maybe if
I can explain what's happening, a more savvy contributor can provide an
answer.
If Word does not have access to the template on which a document is based,
it automatically attachs the template to Normal.dot. However, it does not
update the value displayed in the 'Document template' box in the Templates
and Add-ins dialog box; the original value remains. I suspect that the
documents you're attempting to work with have been "disconnected" from their
template and Word has linked them to the Normal instead, which is why
.AttachedTemplate.FullName doesn't provide a valid result.
I ran into a similar problem when trying to develop "rerun" code for a suite
of templates. I wanted to provide a generic rerun function as part of a
global add-in, but the code that needed to be rerun was carried in the
template on which the document was based. All users had access to both the
add-in and the base template, but because each user had their own copy of the
templates, the path to the template varied between users. Consequently, if
one user sent a document to another and the second user attempted to rerun
the template, the code failed because it could not find the attached template
as specified in the Templates and Add-ins dialog box, which includes the
path. I needed to find a way to get my code to call the code in the template
on the user's machine.
The solution was to parse the value in the 'Document template' box to
determine the actual template name (sans path) and pass that to the rerun
code. This worked a treat, and the code now only fails (gracefully) if the
specified template cannot be found on the user's machine - because it's been
deleted or otherwise modified.
I don't know how this information might help you, but at least you can be
assured that you are on the right track. The information you want to retrieve
is in the 'Document template' box in the Templates and Add-ins dialog. Now
it's just a matter of using C# to get it out.
--
Cheers!
Gordon
Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
:
Thanks for your help thou my problem still persist . However, i read a
response given to a similar question like mine. Apparently, in VB I coud get
the name in the template dialog tool box using
Application.Dialogs(wdDialoToolsTemplates).template but I can't seem to get
similar result in C#. Any ideas on how to get around this? Thank you.
:
I have no documents that I have examined that do not show the correct
template path when used with this macro?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
henry wrote:
thanks Graham for your assistance but I have tried that method
already in C#. for some reason I can use Document.AttachedTemplate so
I decided to use Document.get_AttachedTemplate. However, both method
call are thesame but they always return Normal.dot template which is
not what i am looking for. The documents that I am working on, have
thier template on a server and you can see the correct path when
using Microsoft Word Application. In my case, I am looking for a way
to extract those paths programatically. Hope I made my point clear?
Please, I will appreciate any help and I will be happy to help with
more clarificationif needed. thank you.
:
Dim sTemplate As String
With ActiveDocument
sTemplate = .AttachedTemplate.FullName
MsgBox sTemplate
End With
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
henry wrote:
Hello,
I have tried to get the template name using
Document.get_AttachedTemplate() but i keep on getting normal.dot for
all the documents that i have tried to open which i am sure is not
the name because when you open these documents using microsoft word
application and check the name of the attached template (Tools -
Templates and Add-Ins), it gives you the original name of these
documents. I will like to know if and how to get the original
template name of a document programmatically.
Thanks for your time nad assistance