VB.NET
Imports Microsoft.Office.Tools.Ribbon
Imports Microsoft.Office.Interop.Excel
Public Class Ribbon1
Private Sub Button1_Click(sender As Object, e As RibbonControlEventArgs) Handles Button1.Click
Dim workbook As Workbook = Globals.ThisAddIn.Application.ActiveWorkbook
Dim worksheet As Worksheet = Globals.ThisAddIn.Application.ActiveSheet
Dim range As Range = Globals.ThisAddIn.Application.Selection
Dim cell As Range = Globals.ThisAddIn.Application.ActiveCell
End sub
C#
using Microsoft.Office.Tools.Ribbon;
using Microsoft.Office.Interop.Excel;
namespace test
{
public partial class Ribbon1
{
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Workbook ActiveBook = Globals.ThisAddIn.Application.ActiveWorkbook;
Worksheet ActiveSheet = Globals.ThisAddIn.Application.ActiveSheet;
Range ActiveCell = Globals.ThisAddIn.Application.ActiveCell;
Range SelectedRange = Globals.ThisAddIn.Application.Selection;