We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,163 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Reference to the current open worksheet

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
1 Day
Discussion Span
9 Months Ago
Last Updated
3
Views
AnkitGuru
Light Poster
40 posts since Jul 2011
Reputation Points: 8
Solved Threads: 5
Skill Endorsements: 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()
Pgmer
Practically a Posting Shark
881 posts since Apr 2008
Reputation Points: 60
Solved Threads: 158
Skill Endorsements: 1

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

G_Waddell
Practically a Master Poster
619 posts since Nov 2009
Reputation Points: 107
Solved Threads: 93
Skill Endorsements: 5

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0844 seconds using 2.69MB