0

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

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

            curSheet.Activate()
            MsgBox(curSheet.Name)
        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

3
Contributors
2
Replies
7
Views
5 Years
Discussion Span
Last Post by G_Waddell
0

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")
 objExcelActiveSheet.Activate()
0

Hi,

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..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.