Class not registered Exception - vb.net

In my web site project I need to create an excel file in Server site. Thus I uese the following.
Try
Dim xlApp As Excel.Application = New Microsoft.Office.Interop.Excel.Application()
If xlApp Is Nothing Then
srvHandler.ErrorAnswer = "Excel is not properly installed!!\r\n CreateExcel xlApp"
ServerHandler._InnerError += srvHandler.ErrorAnswer
_Default.errorCall = True
Return
End If
'Dim xlWorkBooks As Excel.Workbooks = xlApp.Workbooks
Dim xlWorkBook As Excel.Workbook = xlApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet)
Dim xlWorkSheet As Excel.Sheets = xlWorkBook.Worksheets
Dim misValue As Object = System.Reflection.Missing.Value
xlWorkSheet.Item(1).Name = "Page1"
If xlWorkSheet Is Nothing Then
srvHandler.ErrorAnswer = "ERROR: xlWorkSheet == null!!\r\n CreateExcel xlWorkSheet"
ServerHandler._InnerError += srvHandler.ErrorAnswer
_Default.errorCall = True
End If
The all code it runs excellent in my PC but when I send it to my ISP it produces the problem
At the point of
Dim xlApp As Excel.Application = New Microsoft.Office.Interop.Excel.Application()
It throws me the following error
Create Excel Retrieving the COM class factory for component with CLSID
{00024500-0000-C000-000000000046} failed due to the following error:
80040154 Class not registered Exception
I try few ways to overcome but was worthless
Is there someone to assist me on this?

I don't think they have Excel installed.
Or if they have during install you have to enable .NET support (at least you had to do it in Office 2003 if I remember correctly).

Related

vb6 Extracts to MS Excel 2013

So my company is transition from 2007 to 2013 - and we have some reports writting in VB6 applications where do extract data from database and write it to excel. It seems that there is some changes that were made and they're this a very difficult process...
This is how I create the declarations for some of my extracts...This code is in my VB6 application!
dim xlsheet1 as Excel.Worksheet ' i have OPTION EXPLICIT and do this at the top
In my function to actually write this report I do this....
Set xlApp = New Excel.Application
set xlBook = xlApp.Workbooks.Add
Set xlSheet1 = xlBook.Worksheets.Add
This worked in Office 2007 - but now it seems to hang up on Set xlBook = xlApp.Workbooks.Add
Any idea?
I was facing the same issue when we migrated from Windows XP to Windows 7. The application was not able to create the excel files.
I changed the declaration from "ExcelSheet" to Object
Dim xlApp as Object
Dim xlBook as Object
Then at the time of using it I set it to excel objects
Set xlApp = New Excel.Application
Set xlBook = New Excel.Workbooks.Add
Hope this will work for you !!!

Excel Object generates error after the application is published

My VB.NET Windows forms application is writing data into excel file. It works without any error in development environment. The excel file gets created with data.
But when the application is deployed/Published. It gives error : "Object reference not set to an instance of an object" at xlWorkBook.SaveAs
Error is confusing. Is it a permission issue? Any help.
Below is the code:
Dim xlApp As Excel.Application = New Excel.Application
xlApp.SheetsInNewWorkbook = 1
Dim xlWorkBook As Excel.Workbook = xlApp.Workbooks.Add
Dim xlWorkSheet As Excel.Worksheet = CType(xlWorkBook.Worksheets.Add(), Excel.Worksheet)
xlWorkSheet.Name = "Sample1"
xlWorkSheet.Cells(1, 1) = "TestData1"
xlWorkSheet.Cells(1, 2) = "TestData2"
xlApp.DisplayAlerts = False
xlWorkBook.SaveAs(gExcelFileName, Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, Type.Missing, Type.Missing, _
Excel.XlSaveAsAccessMode.xlNoChange, Excel.XlSaveConflictResolution.xlLocalSessionChanges)
The solution I found for this issue is to change the folder location in the variable "gExcelFileName" to a local folder on the machine where it is installed. It works now. I think it is a permission issue.
Did you publish your application with excel interop dll? different version of excel may have different parameter, if you don't want to publish your application with excel dll, try to use named parameter:
xlWorkBook.SaveAs(FileName:=gExcelFileName,
FileFormat:=Excel.XlFileFormat.xlWorkbookDefault,
AccessMode:=Excel.XlSaveAsAccessMode.xlNoChange,
ConflictResolution:=Excel.XlSaveConflictResolution.xlLocalSessionChanges)

Why Windows Forms app doesn't save the file to folder

I have a Windows Forms application. In this application I save a Excel file to folder. This is the function that save the file:
Public Sub ExportToXls(ByRef dt As DataTable, ByRef path As String)
On Error Resume Next
'I use Microsoft.Office.Interop.Excel version = 12
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
xlApp = New Microsoft.Office.Interop.Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = xlWorkBook.Sheets(1)
For i1 As Integer = 0 To dt.Columns.Count - 1
xlWorkSheet.Cells(1, i1 + 1) = dt.Columns(i1).Caption
Next
For i1 As Integer = 0 To dt.FieldCount - 1
xlWorkSheet.Cells(2, i1 + 1) = dt.Fields(i1)
Next
Dim fi As New FileInfo(path)
If fi.Exists Then
fi.Delete()
End If
' Default path is X:\WMisch.xls
' here on X: I have all rights.
xlWorkSheet.SaveAs(Filename:=path, FileFormat:=Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel8)
xlWorkBook.Close()
xlApp.Quit()
xlApp = Nothing
xlWorkBook = Nothing
xlWorkSheet = Nothing
On Error GoTo 0
End Sub
All works fine on more that 1 PC/servers but on one Server, with Windows Server 2008 R2 Standard, DOESN'T WORK (doesn't save the file to path X:\WMisch.xls). Here, on this server is installed Office 2003 but I installed also MS Office Interop version 12.
Can anybody say me where is the problem?
Thanks!
I see you're using On Error Resume Next. Rather use a Try..Catch statement. This might help you find you error.

Avoiding "Microsoft Excel" prompt

I'm writing the following bits of code for a SaveFile Dialog box in Visual Basic 2010.NET. The code works well as the XLSX file is created and opens in Microsoft Excel. However, the problem that I am having is that if the program overwrites a file, the user is getting two prompts. One prompt is from the program's own SaveFile dialog confirming the choice. The other is from Microsoft Excel asking you the same. It's as if the program is running in the background.
Does anyone know how I can write this code to save the file as an Excel file?
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Frm1
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
Dim rowcounter As Integer = 1
xlApp = New Excel.Application
xlApp.Visible = False
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = xlWorkBook.Sheets("Sheet1")
xlWorkSheet.Cells(rowcounter, rowcounter) = "Something goes here."
xlWorkSheet.SaveAs(SaveXLS.FileName)
xlWorkBook.Close()
xlApp.Quit()
End Class
I think you want DisplayAlerts=false. Take a look at the answer to this question.

opening excel in vb.net error

what do you think is wrong with the commented line in my vb.net code below? it returns the error message "member not found". thank you.
Public Function tae(ByVal SourcePath As String)
Dim oxlApp As Excel.Application
Dim oxlBook As Excel.Workbook
Dim oxlSheet As Excel.Worksheet
oxlApp = CType(CreateObject("Excel.Application"), Excel.Application)
oxlBook = CType(oxlApp.Workbooks.Open(SourcePath), Excel.Workbook) //somethings wrong here
oxlSheet = CType(oxlBook.Worksheets(1), Excel.Worksheet)
oxlApp.Workbooks.Close()
oxlApp.Quit()
End Function
i tried to add the following references and its now ok:
ms excel x object library
ms office x object library
visual basic for applications