[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VBA Winword: AttachedTemplate.FullName doesn't work

Posted on 2011-05-12
11
Medium Priority
?
800 Views
Last Modified: 2012-05-11
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
Comment
Question by:abfinfo
  • 7
  • 4
11 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 35747759
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
 

Author Comment

by:abfinfo
ID: 35748311
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 35748362
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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Comment

by:abfinfo
ID: 35750009
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 35750094
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
 

Author Comment

by:abfinfo
ID: 35750382
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
 

Author Comment

by:abfinfo
ID: 35752217
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
 

Author Comment

by:abfinfo
ID: 35829617
Is there really NO solution to get this done via VBA?
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 35829714
Looking about a bit I see a dialog so what do you get if you try:

application.dialogs(wddialogtoolstemplates).template

Chris
0
 

Author Closing Comment

by:abfinfo
ID: 36145770
Thanks for your help, this works fine :)
0
 

Author Comment

by:abfinfo
ID: 36151056
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

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question