Chhatrapati Sharma
Chhatrapati Sharma

Reputation: 623

how to select worksheet of workbook in VB

I have written code in C# and then converting it in VB using online converter tool

C# Code :-

ExcelObj = new ExcelShet.Application();
ExcelShet.Workbook theWorkbook = ExcelObj.Workbooks.Open(filepath);
ExcelShet.Sheets sheets = theWorkbook.Worksheets;
ExcelShet.Worksheet worksheet = (ExcelShet.Worksheet)sheets.get_Item(1);

Converted VB Code

Dim ExcelObj As New ExcelShet.Application()
Dim theWorkbook As ExcelShet.Workbook = ExcelObj.Workbooks.Open(filepath)
Dim sheets As ExcelShet.Sheets = theWorkbook.Worksheets
Dim worksheet As ExcelShet.Worksheet = DirectCast(sheets.get_Item(1), ExcelShet.Worksheet)

now issue is- VB doesn't have function get_item(object index)

    Dim worksheet As ExcelShet.Worksheet = DirectCast(sheets.get_Item(1), ExcelShet.Worksheet)

does any one know how to select sheet as like I am doing in C# or which method I should use instead of get_item(object index)

Upvotes: 0

Views: 4195

Answers (1)

rory.ap
rory.ap

Reputation: 35260

You can reference the item using Sheets(1) because Item is the default property. Thus, Sheets.Item(1) works as well.

Upvotes: 2

Related Questions