View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Raphael Saccomani Raphael Saccomani is offline
external usenet poster
 
Posts: 3
Default How to get actual sheet in my workbook?

Hello Guys!

I solved my problem! :)

In the Excel Addin class have the method this.Initialize();

i go to definition and see that he give the Excel Application class:

this.GetHostItem<Microsoft.Office.Interop.Excel.Ap plication(typeof(Microsoft.Office.Interop.Excel.A pplication), "Application");

then i create a simple static class that have one member type of
Microsoft.Office.Interop.Excel.Application

and i can use this class in my ribbon control:

private void button1_Click(object sender, RibbonControlEventArgs e)
{
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet workSheet;
Excel.Range oRng;

try
{

oXL = Functions.m_app;





//Get actual workbook.
oWB = Functions.m_app.ActiveWorkbook;
workSheet = (Excel._Worksheet)oWB.ActiveSheet;



workSheet.Cells[1, 1]="funcioneiiii";
//MessageBox.Show();
MessageBox.Show(workSheet.get_Range("A1",
"A1").Text.ToString());




}
catch (Exception theException)
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat(errorMessage,
theException.Message);
errorMessage = String.Concat(errorMessage, " Line: ");
errorMessage = String.Concat(errorMessage,
theException.Source);

MessageBox.Show(errorMessage, "Error");
}
}


thanks all for help! :)

God Bless!

"Jacob Skaria" wrote:

http://www.codeproject.com/KB/cs/Exc...ion_in_C_.aspx

If this post helps click Yes
---------------
Jacob Skaria


"Raphael Saccomani" wrote:

Hello all, i am trying to developer a excel addin with Visual Studio
2008/Office 2007 and C#!

my question is:

I create a simple Ribbon control with my button, and in the Button click i
want to get the worksheet [0] (fist) and read some cells to paste this values
in word..

my i have no ideia how to do this, can anybody help me?

Tools:
visual studio 2008, Office addin development

Language:
C#

Office Version:
2007