Grrrrrr
File or assembly name Microsoft.Office.Interop.Excel or one of its dependancies was not found
I am trying to use an app I made on a separate machine than it was developed on. The app exports the contents of a data grid to an excel spreadsheet. On the pc the app was developed on I can do the exporting with success, on the other pc I am getting the above error. I have checked my Assembly directory (c:\windows\assembly) and verified that both machines have the same Microsoft.Office.Interop.Excel file with the same version (11) and the same public key. What is the deal?
This what I am doing
The above works on the pc it was developed on but not on any others. Thanks in advance for any help.
File or assembly name Microsoft.Office.Interop.Excel or one of its dependancies was not found
I am trying to use an app I made on a separate machine than it was developed on. The app exports the contents of a data grid to an excel spreadsheet. On the pc the app was developed on I can do the exporting with success, on the other pc I am getting the above error. I have checked my Assembly directory (c:\windows\assembly) and verified that both machines have the same Microsoft.Office.Interop.Excel file with the same version (11) and the same public key. What is the deal?
This what I am doing
VB.NET:
[/COLOR]
[COLOR=black][SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] Microsoft.Office.Interop[/SIZE]
[SIZE=2][/SIZE]
[SIZE=2][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] intColumn, intRow, intColumnValue [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strFileName [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Excel [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Excel.Application[/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] user [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = Environment.UserName
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] filename [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = InputBox("File Name", "Save As", ".xls")
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] fpath [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = "c:\Documents and Settings\" & user & "\Desktop\" & filename[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] Excel
.SheetsInNewWorkbook = 1
.Workbooks.Add()
.Worksheets(1).Select()
[/SIZE][SIZE=2][COLOR=#008000]'For displaying the column name in the the excel file.
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] intColumn = 0 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] ds1.Tables(0).Columns.Count - 1
.Cells(1, intColumn + 1).Value = ds1.Tables(0).Columns(intColumn).ColumnName.ToString
[/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'For displaying the column value row-by-row in the the excel file.
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] intRow = 0 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] ds1.Tables(0).Rows.Count - 1
[/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] intColumnValue = 0 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] ds1.Tables(0).Columns.Count - 1
.Cells(intRow + 1, intColumnValue + 1).Value = ds1.Tables(0).Rows(intRow).ItemArray(intColumnValue).ToString
[/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2].ActiveWorkbook().SaveAs(fpath)
.ActiveWorkbook.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][SIZE=2]MessageBox.Show("File exported sucessfully.", "Exporting done", MessageBoxButtons.OK, MessageBoxIcon.Information)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][/SIZE][/COLOR][COLOR=black]
The above works on the pc it was developed on but not on any others. Thanks in advance for any help.