Activate Excel App when button click

Add-in Express™ Support Service
That's what is more important than anything else

Activate Excel App when button click
 
Vineeth Paliath




Posts: 34
Joined: 2009-06-19
Hi,

In my excel Addin load and open my application, when i click a button in application i need to activate and bring into view the Excel application how can implement this


Thanks
Posted 29 Jun, 2009 03:17:24 Top
Andrei Smolin


Add-in Express team


Posts: 14115
Joined: 2006-05-11
Hi Vineeth,

Try calling the Activate method available for a number of Excel types. Say, Range.Activate, Workbook.Activate, Worksheet.Activate.

See also Getting help with COM objects, properties and methods.

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 29 Jun, 2009 09:34:27 Top
Vineeth Paliath




Posts: 34
Joined: 2009-06-19
Hi,

Thanks for your reply,


its works sucessfully in word and powerpoint, but i cant find activate() method in Excel

((AddinModule)AddinModule.CurrentInstance).WordApp.Activate();
((AddinModule)AddinModule.CurrentInstance).PowerPointApp.Activate();


please help
Thanks
Posted 29 Jun, 2009 10:03:51 Top
Andrei Smolin


Add-in Express team


Posts: 14115
Joined: 2006-05-11
Hi Vineeth,

Did you try activating a workbook?

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 29 Jun, 2009 10:16:58 Top
Vineeth Paliath




Posts: 34
Joined: 2009-06-19
Hi,

yes i tried to activate workbook it give ambliguity warning between method Excel._workbook.activate() and non_method Excel.workbookEvents.Actiavte() Using method group, and cant get expected result

((AddinModule)AddinModule.CurrentInstance).ExcelApp.ActiveWorkbook.Activate();

Thanks
Posted 30 Jun, 2009 01:35:12 Top
Vineeth Paliath




Posts: 34
Joined: 2009-06-19
Hi,

please give a reply
Posted 01 Jul, 2009 01:16:58 Top
Andrei Smolin


Add-in Express team


Posts: 14115
Joined: 2006-05-11
Hi Vineeth,

Where do you run your code? In an Excel add-in?

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 01 Jul, 2009 10:30:58 Top
Vineeth Paliath




Posts: 34
Joined: 2009-06-19
yes
Posted 02 Jul, 2009 00:56:52 Top
Andrei Smolin


Add-in Express team


Posts: 14115
Joined: 2006-05-11
Hi Vineeth,

The following code works fine for me:


        [DllImport("User32.dll")]
        private static extern bool SetForegroundWindow(IntPtr hWnd);

        private void button1_Click(object sender, EventArgs e)
        {
            Excel.Application ExcelApp = Marshal.GetActiveObject("Excel.Application") as Excel.Application; 
            SetForegroundWindow((IntPtr)ExcelApp.Hwnd);
        }


Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 04 Jul, 2009 09:40:59 Top
Vineeth Paliath




Posts: 34
Joined: 2009-06-19
Hi,

i tried this code but i cant find ExcelApp.Hwnd and WordApp.Hwnd but it will get only in PowerPointApp.Hwnd, what iam missing here?

Thanks for your reply
Posted 06 Jul, 2009 02:43:23 Top