How to get the current open documents in Excel using C#?

天大地大妈咪最大 提交于 2019-12-21 05:22:09

问题


All I need is to get the list of currently open documents in the currently open instance of Microsoft Excel.

But I don't know Excel terminology to know if these documents are called workbooks, or sheets, or windows, etc.

Any ideas


回答1:


Found it (link).

//Excel Application Object
Microsoft.Office.Interop.Excel.Application oExcelApp;

this.Activate ( );

//Get reference to Excel.Application from the ROT.
oExcelApp = ( Microsoft.Office.Interop.Excel.Application ) System.Runtime.InteropServices.Marshal.GetActiveObject ( "Excel.Application" );

//Display the name of the object.
MessageBox.Show ( oExcelApp.ActiveWorkbook.FullName );

//Release the reference.
oExcelApp = null;



回答2:


You're looking for the Workbooks property.



来源:https://stackoverflow.com/questions/2449387/how-to-get-the-current-open-documents-in-excel-using-c

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