LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default C# and Excel: how to get reference to Excel VBA form

Hi,

I am trying to automate work with Excel file that uses macroses and VBA
controls and forms. In particular, Excel file has the button that invokes a
new form when clicking on it.

I can successfully access and get reference to the button, but fails to do
this for the form

My C# code:

....
using Excel = Microsoft.Office.Interop.Excel
using MSForm = Microsoft.Vbe.Interop.Forms;

// start Excel and open the file
Excel.Application oXL = new Excel.Application();
oXL.Visible = true;
Excel.Workbook oWb = (Excel.Workbook)(oXL.Workbooks.Open(file,...));
Excel.Worksheet oSheet = (Excel.Worksheet)oWB.ActiveSheet;

// get reference to the button by its VBA name - works successfully
Excel.OLEObject obj1 = (Excel.OLEObject)(oSheet.OLEObjects("myButton"));
MSForm.CommandButton requestButton = (MSForm.CommandButton)(obj1.Object);

// emulate clicking the button and wait a little until the form appears
....

// trying to get reference to the form that has appeared by its VBA name -
get exception 0x800A03EC
object myForm = oSheet.OLEObjects("myForm");


Question: How can I refer Excel's user form from my C# code?

 
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
excel form. Need data extracted to spreadsheet each time a form co MikeR-Oz Excel Discussion (Misc queries) 4 April 5th 09 05:18 AM
Can a form made in Excel 2002 be converted into a fillable form? Paraclete Excel Discussion (Misc queries) 1 February 20th 07 09:20 PM
Transfer data to form from Excel range upon loading of form. Rob Crawford Excel Programming 2 October 24th 05 03:59 PM
form in excel to be attached to the emails address in the form upon sumission Abdulkader Bhanpurawala via OfficeKB.com Excel Programming 6 July 10th 05 10:48 AM
Reference Access created form in excel Ryan Patch Excel Programming 0 January 31st 04 08:01 PM


All times are GMT +1. The time now is 11:57 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"