PDA

View Full Version : How to find out the AttachedTemplate of files in a folder



debspink
03-04-2011, 04:04 PM
Is it possible to iterate through a list of Word documents (.doc's) in a folder and find out the name of the template attached to each one. I can use either 2003 or preferably 2010?

Thanks.

debspink
03-04-2011, 05:07 PM
Hi, further searching on this forum revealed this article, which after some editing serves my purpose perfectly:

"Process All Documents in a Specified Directory Folder Including Subfolders"

(I was not allowed to add a link!)

Thanks!

debspink
03-10-2011, 04:27 AM
Whilst this served my purpose for a few documents, I need to interogate potentially 1000's. Is it possible to capture the name of the attached template from the document properties without having to actually open the files?

Thanks,

Debs

fumei
03-10-2011, 10:39 AM
Just in Word? No. You have to open them.

Frosty
03-10-2011, 01:12 PM
I was curious about this... and actually, I think there is a way to do it without actually opening Word. However, just because I'm saying it's possible doesn't mean I'm going to write the code :)

Since the document format in 2007/2010 is no longer binary (or, least, very little of it), it is technically possible to, programmatically, do the following:
1. Change a .docx to .zip
2. "read" the contents of the .zip file (specifically, you'd be looking at the docProps\app.xml) and then look for "<Template>yourtemplatename.dotx</Template>"

However, if you're not familiar with how to do all this stuff... it may take you longer to do the research and come up with a solution than it would be to simply start running the code you know works on your 1000 documents.

Also, depending on *where* you're putting this code... (i.e., if you're developing in Word VBA), the end result may actually be slower than if you simply used CreateObject to create a new word process, hid it from view, and did your processing in a hidden process).

So, the short answer is... listen to Fumei/Gerry.

Frosty
03-10-2011, 01:14 PM
Also... it seems that, at least in Windows 7 and Office 2010, I do see a "Template" property in the Details Tab of a right-click properties action.

So that might also mean there is some sort of System object which gives you the file properties, but I'm not terribly familiar with that stuff, so maybe someone else will have that info.

fumei
03-10-2011, 02:19 PM
You may also want to check to see if Dsofile will work for you.

http://support.microsoft.com/kb/224351

I am not sure it will read AttachedTemplate.