1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Excel アドイン VSTO(VB.NET, C#) アクテイブなブック、シートの取得方法 選択中の範囲、セル取得方法

Last updated at Posted at 2020-11-24

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;
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?