以编程方式获取打开的Excel/Word文档的路径 [英] Programatically get path of open Excel/Word-document

查看:126
本文介绍了以编程方式获取打开的Excel/Word文档的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以获取当前在Microsoft Word和Microsoft Excel中打开的文档的路径?

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

我知道如何获取正在运行的Excel或Word实例的PID和窗口句柄,但是我不知道如何获取打开文档的路径.甚至有可能吗?

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?

我认为API会很好,但是我怀疑它是否存在.可能有某种将信息发送到我的应用程序的插件吗? (但是,如果有其他可行的方法,我希望避免在各处安装插件.)

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.)

我更喜欢使用C#来做,但是可以编译成可执行文件的任何东西都是可以的.

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.

推荐答案

有一个名为 Office Interop ...它基本上是用于MS Office的基于COM的接口...,可以在C#中使用.

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

对于Excel,您可以通过 Application.ActiveWorkbook.FullName .

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

对于Word,您可以通过 Application.ActiveDocument.FullName .

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

这篇关于以编程方式获取打开的Excel/Word文档的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆