• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 820
  • Last Modified:

VBA Winword: AttachedTemplate.FullName doesn't work

Hi,

I've got a problem: I've coded a little script which parses trough the directories and open all word documents. I open the documents like this:

Dim sDoc as String
Dim WdDoc as Word.Document

sDoc = "C:\Templates\document.doc"
Set WdDoc = Documents.Open(sDoc)
sAttachedTemplate = WdDoc.AttachedTemplate.FullName

Open in new window

This works without any problems IF the template exists. But my script should get the attached template path correctly for documents which are attached to non existing templates. The target of the script is to build a list with all documents and their attached template.

The Problem is if the template doesn't exist, it displays it correctly when I open the related dialog box via Word, but not when I try to access the path via AttachedTemplate.FullName. If it doesn't exist, it gives me the value from the default normal.dotx of my user.

Is there a solution for this problem?

Best regards,
abfinfo
0
abfinfo
Asked:
abfinfo
  • 7
  • 4
1 Solution
 
Chris BottomleySoftware Quality Lead EngineerCommented:
I'm wondering why that is a problem?, not a silly question just need to understand why you don't want the attached template name for the deault files.

Chris
0
 
abfinfoAuthor Commented:
I have to parse a few hundereds of documents and have to know the exact path of the attached template. Winword (GUI) shows me the right template, but I can't get this path via VBA because it doesn't display me the correct path. It just falls back to the default template path.

Why I want this? Because it's the main target of my little tool to list each document with the attached template. The default template is nice to use, but not when I only want the information which is the exact attached template.
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Hmmm. therein lies my problem, I have just confirmed and I always get the correct template with the full path when I use ttachedTemplate.FullName
.

Can you give an example of what happens for you, i.e. do you get a part path, wrong path, wrong everything or what?

Chris
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
abfinfoAuthor Commented:
I think an example would be the best way:

Let us assume there is a wordfile called document.doc in c:\Temp
This Document is assigned to the template at \\server1.internal.ch\templates\templat.dot
Now the template at \\server1.internal.ch\templates\templat.dot doesn't exist anymore
But I have a VBA script (based on the code from above) which opens c:\Temp\document.doc and tries to get the temlate via document.
The problem is now I've got as path something like c:\Users\xy\Application Data\Microsoft\Word\normal.dotxm
This is the default template of my office installation. But it should return \\server1.internal.ch\templates\templat.dot (what I can see when I take a look over the Word GUI)
It works without any problems if \\server1.internal.ch\templates\templat.dot exists, but if not, then it return the wrong path.

Did you checked exactly this? Then I would have a bug in my code and have to post tomorrow the real code (I'm at home atm).
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Thanks for that I understand now, this a default function in that with the attached document not found it drops back to the default.  I do not believe access to the file path is available hence the file nme for the template is all that is available.

If the name of the files vary, then you could access the template name using dsofile, (http://support.microsoft.com/kb/224351).

Chris
0
 
abfinfoAuthor Commented:
Thanks for your answer.

Hmmm when I understand you correctly then there isn't a way to access the correct template path from a wordfile if the template at this path doesn't exist?

This would be bad, because Word itself can display this path without any problems. So I think there must be a possibilty to access this information.

I don't have any experience with dsofile. Is it really possible to do this with vba? are there some examples how that can be done?
0
 
abfinfoAuthor Commented:
Addition: If it's not possible to get the correct value over a function, is it possible to access the value of the dialog box in word? It wouldn't be as performant like accessing the value over a function, but if there is a way to open the dialog box and grab the value from there, this would be ok too.
0
 
abfinfoAuthor Commented:
Is there really NO solution to get this done via VBA?
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Looking about a bit I see a dialog so what do you get if you try:

application.dialogs(wddialogtoolstemplates).template

Chris
0
 
abfinfoAuthor Commented:
Thanks for your help, this works fine :)
0
 
abfinfoAuthor Commented:
I've to add that this only works with the old .doc format. With >= Office 2007, Word has a auto-fallback in the dialog too.

If there is any possibility to get the real path with .docx too, it would be really great.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now