If a DOC file is being opened by MS Word, is there any way for an external program to get the full path of the DOC file? I tried to use GetCommandLineA() but it yields me no result, just “”C:\Program Files\Microsoft Office\Office12\WINWORD.EXE” /n /dde”. I also read an article at http://www.withinwindows.com/2008/08/31/taming-microsoft-word-2007s-file-associations-and-document-windows-part-one/, but I don’t know how to get that DDE messages. Would you please tell me how?
Share
You need to get a hook into the Word object model (e.g. through .Net / Office Interop or directly via COM). Once you have a reference to the document, use its FullName property. If the document may be across the network on a server or from a database, it is possible it could have characters in the filename (such as “-“)which are invalid to whatever platform you are downloading it to. If this is the case, strip the name of invalid file path characters according to the platform.
There are a few defensive techniques for getting the name.