I have the following code for processing the contents of an Excel worksheet, however I'm having a little difficulty inserting a new row
.
Its at the last line that the code fails with the exception message;
"Cannot shift objects off sheet"
Can anybody please tell me what I'm doing wrong?.
![[sadeyes] [sadeyes] [sadeyes]](/data/assets/smilies/sadeyes.gif)
Code:
Dim myExcel As New Excel.Application
Dim myWorkBook As Excel.Workbook
Dim myWorkSheet As Excel.Worksheet
Dim XLData As String
Dim IRow As Integer
myWorkBook = myExcel.Workbooks.Open(myXLSFile)
myWorkSheet = myWorkBook.Worksheets.Item(1)
IRow = 1
XLData = CType(myWorkSheet.Cells(IRow, 1), Excel.Range).Text
Do While (XLData <> "A New Record")
IRow = IRow + 1
XLData = CType(myWorkSheet.Cells(IRow, 1), Excel.Range).Text
Loop
'Add new record just prior to row with "A New Record"
myWorkSheet.Rows.Insert(IRow)
Its at the last line that the code fails with the exception message;
"Cannot shift objects off sheet"
Can anybody please tell me what I'm doing wrong?.