Hi,
I am creating a excel file using VB Dot Net to fetch data from SQL.
It works well & code is 100% complete
the only problem is how to give reference to excel sheet using its name property rather than displayed name
like I am using Globals.Thisworkbook.Sheets("Database")
now my requirement is what if user changed the sheet name from Database to say DB or whatever. My code fails
I tried lot to give reference to sheet number programatically but all in vain
In VBA I used to give reference like Sheet1.select instead of Sheets("Database").select so that my code run irrespective of sheet name.
Kindly suggest me the same way in VB DOT NET
I tried Globals.thisworkbook.sheets(1)
Globals.thisworkbook.worksheets.item(1)
but all fails even if user change sheet positions.
Pl . Pl. help me its urgent
Select Sheet in VB dot net
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

PJ MartinsRank #2,548 · 548 reputationPosted May 26, 2010, 5:28 PM EDT
Anand BohraRank #9,215 · 209 reputationPosted May 26, 2010, 10:48 PM EDT
the equivalent VB code is
Globals.ThisWorkbook.Worksheets.Item(1)
but the same is populated based on total sheets in workbook counting from left to right
so whatever sheet be in first positions will be taken irrespective of sheet name or its program name
I want to select particular sheet based on its named property rather than caption
like in VBA we use Sheet1.select instead of Sheets("ABC").select
PJ MartinsRank #2,548 · 548 reputationPosted May 27, 2010, 5:12 AM EDT