PDA

View Full Version : Trouble reading built-in properties of inactive documents (Help - just five lines!)



rgmatthes
12-31-2009, 01:41 PM
Hello -

This subroutine tries to retrieve the author name from the built-in document properties of an unopened document ("test.doc") and display it in a messagebox, but it doesn't work unless the document is currently open. Do you see how I can fix this for upopened documents?





Sub MsgBoxAuthorName()

Dim AuthorName As String

AuthorName = Documents("C:\test.doc").BuiltInDocumentProperties(wdPropertyAuthor)
MsgBox AuthorName

End Sub

Is there a simple solution for reading the built-in properties of unopened documents?

Or relatedly, if the document HAS to be open for this to work (discouraged), is there a way I can automatically close it without saving, no matter what?

THANKS!!!!

fumei
12-31-2009, 02:09 PM
Let's start with:

"Or relatedly, if the document HAS to be open for this to work (discouraged), is there a way I can automatically close it without saving, no matter what?"

Yes. Simply .Close it with wdDoNotSaveChanges

As for getting doc properties on unopened files, use DSOfile.

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

In versions prior to 2007 (which removed FileSearch) you may be able to use FileSearch.

Paul_Hossler
01-02-2010, 08:08 AM
fumei -- is there a way to tell is DSOfile is available on a computer? Some one using one of my templates, may not have it istalled if it requires that they run the Installer from that link first.

Paul

rgmatthes
01-04-2010, 08:27 AM
Let's start with:

"Or relatedly, if the document HAS to be open for this to work (discouraged), is there a way I can automatically close it without saving, no matter what?"

Yes. Simply .Close it with wdDoNotSaveChanges

As for getting doc properties on unopened files, use DSOfile.

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

In versions prior to 2007 (which removed FileSearch) you may be able to use FileSearch.

The holidays prevented me from responding to this earlier. Thanks for your help, fumei! Closing with wdDoNotSaveChanges is enough for me. :)

fumei
01-04-2010, 10:08 AM
Hi Paul. That is one of the issues for using DSO. It requires an install on thelocal machine, so if your code uses it, and it is not on that machine, your code will fail.

You could check against the References. I understand your issue. I use DSO for my own purposes, but I do not use it for documents or templates in my work environment as DSO is not an approved install. We have a very tight corporate environment. They check across the network regularly for any software not formally approved. While I have a wider leanway, the majority of our users do not.