Hi,
This is my code to open/read/write and save excel file, but unable to select the worksheet (it does not mattter ws index or ws name was entered), only select the first sheet. Please help, any advices are appreciated.
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim bOpen As Boolean
xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
xlBook = CType(xlApp.Workbooks.Open(sSpec_Path), Microsoft.Office.Interop.Excel.Workbook)
xlApp.DisplayAlerts = False : bOpen = True
If bOpen Then
xlSheet = CType(xlBook.Worksheets(1), Microsoft.Office.Interop.Excel.Worksheet) 'Unable to select any worksheet event 2, 3 was entered or ws name
With xlSheet.Application
...... in here i can read/write/
endwith
xlBook.Close() : xlApp.DisplayAlerts = True : xlApp.Quit()
|