Programatically get path of open Excel/Word-document

我怕爱的太早我们不能终老 提交于 2019-12-11 11:32:24

问题


Is there any way to get the path of documents currently open in Microsoft Word and Microsoft Excel?

I know how I can fetch the PID and the window handle for the running instance of Excel or Word, but I have no idea how to get the path of the open document. Is it even possible?

I am thinking that an API would be nice, but I doubt it even exists. Perhaps some kind of plugin that sends information to my application is a possibility? (But if any other way is possible, I'd like to avoid having to install plugins everywhere.)

I would prefer to do it using C#, but anything that can be compiled into an executable is alright.

And just in case someone thinks this sounds fishy, it is not to be used for anything remotely illegal. It is for a data collection system at work.


回答1:


There is an API called Office Interop... it is basically a COM based interface for MS Office... and can be used from C# .

For Excel you can get the current file including path via Application.ActiveWorkbook.FullName.

For Word you can get the current file including path via Application.ActiveDocument.FullName.



来源:https://stackoverflow.com/questions/8963529/programatically-get-path-of-open-excel-word-document

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!