Imports Excel = Microsoft.Office.Interop.Excel
Public Sub GenerateSpreadsheet()
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook = xlApp.Workbooks.Add
Dim xlFixedSheet As Excel.Worksheet
Dim xlVariableSheet As Excel.Worksheet
xlApp.Caption = System.Guid.NewGuid.ToString.ToUpper
xlBook = xlApp.Workbooks.Add
xlFixedSheet = xlBook.Worksheets.Item(1)
xlVariableSheet = xlBook.Worksheets.Item(2)
CType(xlFixedSheet, Excel._Worksheet).Activate()
I am running the above code on a program that runs over a network. There are 10 users, 9 are running Excel 2003 and 1 is running Excel 2007. The program runs fine on the machines running Excel 2003 but on the one running Excel 2007 I receive an Invalid Index error when it attempts to run the following code: xlVariableSheet = xlBook.Worksheets.Item(2). I have been scratching my head on this one for a week and have been unable to come up with anything. Does anyone have any ideas or suggestions? I have ran the code on a test box that has Excel 2007 installed and it ran fine.
Public Sub GenerateSpreadsheet()
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook = xlApp.Workbooks.Add
Dim xlFixedSheet As Excel.Worksheet
Dim xlVariableSheet As Excel.Worksheet
xlApp.Caption = System.Guid.NewGuid.ToString.ToUpper
xlBook = xlApp.Workbooks.Add
xlFixedSheet = xlBook.Worksheets.Item(1)
xlVariableSheet = xlBook.Worksheets.Item(2)
CType(xlFixedSheet, Excel._Worksheet).Activate()
I am running the above code on a program that runs over a network. There are 10 users, 9 are running Excel 2003 and 1 is running Excel 2007. The program runs fine on the machines running Excel 2003 but on the one running Excel 2007 I receive an Invalid Index error when it attempts to run the following code: xlVariableSheet = xlBook.Worksheets.Item(2). I have been scratching my head on this one for a week and have been unable to come up with anything. Does anyone have any ideas or suggestions? I have ran the code on a test box that has Excel 2007 installed and it ran fine.