简体   繁体   中英

How to restore a minimized excel programmatically in c#

I want to activate or make it visible(restore) of an existing open/minimized excel using a button click to avoid user open in another new instance.

For example, an workbook_A was minimized, the user click a button and the workbook_A will restored as usual instead of open in another new instance.

I tried to use below codes:

Excel.Application oExcelApp;
this.Activate();
oExcelApp =     (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
oExcelApp.Visible = true;

But it's only open the empty excel.application, any idea how can I restore back my opened excel?

Please advice.. Thanks

Just simply go through workbooks collection and make their window state = maximaze like that

foreach (Excel.Workbook item in oExcelApp.Workbooks)
{
  item.Windows[1].WindowState = Excel.XlWindowState.xlMaximized;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM