I am getting this error when my vb.net 2005 app trys to create an Excel file.
I have the Com object reference in my program. The program uses the COM
object to create the Excel File so i can use the oledb to populate the file.
The program runs fine on my dev machine and server type machine but once i
try to run this app on a desktop or a workstation,(NONE OS Server type
installation), it will return this error 'Could not load file or assembly
'Microsoft.office.Interop.Excel,Version=11.0.0.0,
Culture=neutral,PublicKeyToken=71e9bce111e9429c' or one of its dependencies.
The system cannot find the file specified'
On my dev machine i have window 2003 server, .frameworks 2.0 beta,office
2003;excel SP1 , VS2005 beta.
The desktop machine have either framework2.0 beta or framework2.0 release.
still same error.
Any help would be great.
Binh
Here is my code:
Imports System
Imports System.IO
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports Microsoft.VisualBasic
Imports Microsoft.Office.Interop.Excel
Private Sub WriteToExcel(ByVal filename As String)
Dim MyExcel As New Microsoft.Office.Interop.Excel.Application
Dim oWorkbooks As Microsoft.Office.Interop.Excel.Workbooks =
MyExcel.Workbooks
Dim theWorkbook As Microsoft.Office.Interop.Excel.Workbook =
oWorkbooks.Add
Dim oSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim xlsSaveFile As String = filename
'If file already exists, remove it
If File.Exists(xlsSaveFile) Then File.Delete(xlsSaveFile)
Try
'theWorkbook = oWorkbooks.Open(xlsSaveFile)
oSheet = MyExcel.ActiveSheet
oSheet.Name = "Exception"
oSheet.Cells(1, 1) = "PO Filename"
oSheet.Cells(1, 3) = "Reason"
oSheet = MyExcel.Sheets(2)
oSheet.Name = "Missing Email Art"
oSheet.Cells(1, 1) = "PO Filename"
theWorkbook.SaveAs(xlsSaveFile)
theWorkbook.Close()
MyExcel.Quit()
GC.Collect()
GC.WaitForPendingFinalizers()
Catch ex As Exception
Throw New Exception("Error creating Excel spreadsheet:" &
ex.Message.ToString())
Finally
oSheet = Nothing
theWorkbook = Nothing
oWorkbooks = Nothing
MyExcel = Nothing
End Try
Dim x As Integer
Dim mycommand As OleDbCommand
Dim myconnection As OleDbConnection
Dim cnStr As String = "provider=Microsoft.Jet.OLEDB.4.0; data
source=" & filename & "; Extended Properties=Excel 8.0;"
myconnection = New OleDbConnection(cnStr)
myconnection.Open()
For x = 0 To lbException.Items.Count - 1
Dim sql As String
Dim tmpvalue1 As String
tmpvalue1 = Replace(lbException.Items(x), "'", "' + chr(39) +
'", 1)
sql = "insert into [Exception$] ([PO FileNAme],[Reason])
values('" & tmpvalue1 & "','')"
mycommand = New System.Data.OleDb.OleDbCommand(sql, myconnection)
mycommand.ExecuteReader()
Next
For x = 0 To lbSO_NoArtRP.Items.Count - 1
Dim sql As String
Dim tmpvalue2 As String
tmpvalue2 = Replace(lbSO_NoArtRP.Items(x), "'", "' + chr(39) +
'", 1)
sql = "insert into [Missing Email Art$] ([PO FileNAme])
values('" & tmpvalue2 & "')"
mycommand = New System.Data.OleDb.OleDbCommand(sql, myconnection)
mycommand.ExecuteReader()
Next
For x = 0 To lbSO_NoProofRP.Items.Count - 1
Dim sql As String
Dim tmpvalue3 As String
tmpvalue3 = Replace(lbSO_NoProofRP.Items(x), "'", "' + chr(39) +
'", 1)
sql = "insert into [Missing PaperProof$] ([PO FileNAme])
values('" & tmpvalue3 & "')"
mycommand = New System.Data.OleDb.OleDbCommand(sql, myconnection)
mycommand.ExecuteReader()
Next
myconnection.Close()
End Sub
Randall Arnold - 03 Jan 2006 17:23 GMT
I have the same problem, only it occurs when I try to deploy from a server.
I sure wish someone could help on this...
Randall Arnold
>I am getting this error when my vb.net 2005 app trys to create an Excel
>file.
[quoted text clipped - 113 lines]
>
> End Sub
Ashok - 28 Mar 2008 13:19 GMT
Have you installed the Office Primary Interop Assemblies on the test machine?
This can be done either through the office install or by downloading and
installing them from here
http://msdn2.microsoft.com/en-us/library/aa159923(office.11).aspx
install it , and your application will work fine.
From http://www.developmentnow.com/g/21_2005_12_0_0_650303/Could-not-load-File-or-Ass
embly-Microsoft-office-Interop-Excel.ht