View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
royend[_2_] royend[_2_] is offline
external usenet poster
 
Posts: 4
Default How do I reference a Worksheet from a Form (Add-in for Excel 2003)

Hi.
How can I reference the Worksheet (and Application) from a Form in an Add-in
for Excel 2003? I have tried this code:

Excel.Worksheet sheet = (Excel.Worksheet)this.Sheets["Sheet2"];
sheet.Select(Type.Missing);
Excel.Range newFirstRow = sheet.get_Range("A1", Type.Missing);
newFirstRow.Value2 = "This text was added by using code";

But I only get an error telling me that 'Form1' does not contain a
definition for 'Worksheets'.

I also tried this:

Excel.Worksheet sheet =
((Excel.Worksheet)Application.ActiveSheet);

Which led to the following error:
'System.Windows.Forms.Application' does not contain a definition for
'ActiveSheet'

My goal is to do some calculations with my Add-in, present a summary of the
calculations in the Add-in while saving all calculations in the Excel calling
the Add-in.
I am using Visual Studio 2008 for programming an Add-in for Excel 2003.