This is an issue where when the code hits ExcelObj = CreateObject("Excel.Application") line it throws the "Cannot create ActiveX component" error. Does anyone know why this is happening?


Sub SavePartNumbersInSession()
Dim ExcelObj As Object
'Dim ExcelBook As Object
'Dim ExcelSheet As Object
Dim i As Integer
Dim j As Integer
'Dim cells As Object

ExcelObj = CreateObject("Excel.Application")
'ExcelSheet = CreateObject("Excel.Sheet")

ExcelObj.WorkBooks.Open(sPath & "UploadedFiles\" & System.IO.Path.GetFileName(MyFile.PostedFile.FileName))

'ExcelBook = ExcelObj.Workbooks(1)
'ExcelSheet = ExcelBook.WorkSheets(1)

i = 1
j = 2

'cells = ExcelBook.WorkSheets(1).cells

Session("PartNumbers") = ""

Do Until ExcelObj.Workbooks(1).WorkSheets(1).cells(1, i).value & "" = ""

If ExcelObj.Workbooks(1).WorkSheets(1).cells(1, i).value = "Part Number" Then
ExcelObj.Workbooks(1).WorkSheets(1).UsedRange.Columns(i).NumberFormat = "@"

Do Until ExcelObj.Workbooks(1).WorkSheets(1).cells(j, i).value & "" = ""
'If IsNumeric(ExcelObj.Workbooks(1).WorkSheets(1).cells(j, i).value) Then
If Session("PartNumbers") <> "" Then
Session("PartNumbers") &= "|"
End If

Session("PartNumbers") &= CStr(ExcelObj.Workbooks(1).WorkSheets(1).cells(j, i).value)
' End If


j = j + 1
Loop
End If

i = i + 1
Loop

ExcelObj.DisplayAlerts = False
ExcelObj.Workbooks(1).Close()
ExcelObj.Quit()

ExcelObj = Nothing
End Sub