Hi Guys!!

I am creating an addin in Excel using VB.Net.
I want to access the current worksheet using a ribbon designer.

I have tried all sorts but to no avail. Also all the resources that I have checked are
providing solutions by adding or opening new workbook.

What I want is to create a reference to the active worksheet.

For example by adding what we get is

Imports Microsoft.Office.Tools.Ribbon
Imports Microsoft.Office.Interop
Imports System.Windows.Forms

Dim currApp As Excel.Application
Dim curSheet As Excel.Worksheet
Dim curSheets As Excel.Sheets
Dim curBook As Excel.Workbook
Dim curBooks As Excel.Workbooks

Private Sub Ribbon1_Load(ByVal sender As Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonUIEventArgs) Handles Me.Load

            currApp = New Excel.Application
            curBooks = currApp.Workbooks
            curBook = curBooks.Add
            curSheets = curBook.Worksheets
            curSheet = curSheets(1)

        Catch ex As Exception
            MsgBox(ex.Message & vbCrLf & vbCrLf & ex.ToString)
        End Try

    End Sub

Give me some clue as how to start, Again I want to reference to currently active sheet

Recommended Answers

All 2 Replies

Try something like below. I am assuming you will be knowing the sheet name

 Dim objExcelworkbook As Microsoft.Office.Interop.Excel.Workbook
 Dim objExcelActiveSheet As Microsoft.Office.Interop.Excel.Worksheet
 objExcelActiveSheet = objExcelworkbook .Sheets("TestPage")


I haven't done this for a few years but I'm fairly sure there is a Worksheets.ActiveSheet method or .ActiveSheets(index) or something like it..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.