Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default howto click button using .net

hello everyone,
how do i click a commandbutton using .net and the Excel 11.0 Object Library

this is my code, but the error says it cannot cast system.__comobject to the
excel.oleobjectclass

Microsoft.Office.Interop.Excel.Application appExcel = new
Microsoft.Office.Interop.Excel.Application();
", Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
Microsoft.Office.Interop.Excel.Worksheet wsSetup =
(Microsoft.Office.Interop.Excel.Worksheet)appExcel .Sheets["Sheet1"];
Microsoft.Office.Interop.Excel.OLEObjectClass objRefresh =
(Microsoft.Office.Interop.Excel.OLEObjectClass)wsS etup.OLEObjects("CommandButton1");
//After casting it i guess i want to call the click method
//objRefresh.Click() or something
string strType = objRefresh.OLEType.ToString();
appExcel.ActiveWorkbook.Close(false, Type.Missing, Type.Missing);
appExcel.Quit();
MessageBox.Show(strType);

thank you for your help


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default howto click button using .net

i found some code that used msforms to cast the object
so i changed my code to:


Microsoft.Office.Interop.Excel.Application appExcel = new
Microsoft.Office.Interop.Excel.Application();

", Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);

Microsoft.Office.Interop.Excel.Worksheet wsSetup =
(Microsoft.Office.Interop.Excel.Worksheet)appExcel .Sheets["Sheet1"];

CommandButtonClass cbRefresh =
(CommandButtonClass)wsSetup.OLEObjects("CommandBut ton1"); //this line fails

//Microsoft.Office.Interop.Excel.OLEObjectClass objRefresh =
(Microsoft.Office.Interop.Excel.OLEObjectClass)wsS etup.OLEObjects("CommandButton1");

string strType = cbRefresh.Name;

appExcel.ActiveWorkbook.Close(false, Type.Missing, Type.Missing);

appExcel.Quit();

MessageBox.Show(strType);



thank you for your help


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Customizing right-click button stragger Excel Discussion (Misc queries) 2 November 24th 06 05:33 PM
Create floating button based on button click in menu ExcelMonkey Excel Programming 2 October 12th 05 06:43 PM
On Button Click(Help!) jpizzle[_2_] Excel Programming 1 June 3rd 05 11:32 AM
VBA button click need help. Need LEN help. Nigel Cummins Excel Programming 4 July 11th 03 08:52 PM
VBA button click need help. Need LEN help. Nigel Cummins Excel Programming 0 July 11th 03 09:53 AM


All times are GMT +1. The time now is 12:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"