Fergus Cooney said:
Hi Magnus,
On my system (VS2002, Office 2000), I've got various COMs
Microsoft Excel 9.0 Object Library
C:\Program Files\Microsoft Office\Office\Excel9.tlb
Interop.Excel in my project directory.
Microsoft Office 9.0 Object Library
C:\Program Files\Microsoft Office\Office\MSO9.tlb
Interop.Office in my project directory.
Microsoft Office 10.0 Object Library
C:\Program Files\Common Files\Microsoft Shared\Office\MSO.tlb
Microsoft.Office.Core in the GAC
C:\WINNT\assembly\GAC\Office\7.0.3300.0__b03f5f7f11d50a3a\Office.dll
And one .NET
office
C:\WINNT\Microsoft.NET\Framework\v1.0.3705\office.dll
Do you have a choice or just the one?
Regards,
Fergus
I have these choices available to me in the COM reference window, for office
and excel.
Microsoft Excel 9.0 Object Library,
Microsoft Excel 5.0 Object Library,
Microsoft Office 10.0 Object Library,
Microsoft Office 9.0 Object Library
I have tried both 9.0 and 5.0 for excel, I am not aware of any possibilities
for excel in office, but tried adding reference to 10 object library without
any luck. I have also tried adding reference to office in .NET.
Took out relevant code from Joe Fallon's code, and this is what I have now
which also fails. I have added some (" '#Comment "), be sure to check it
out.
Hope someone can help.
<CODE>
Dim oExcel As Excel.Application
Dim oBooks As Excel.Workbooks
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
Try
'get a running instance of Excel - this minimizes the number of instances
of Excel in memory!
oExcel = CType(GetObject(, "Excel.Application"), Excel.Application)
Catch ex As Exception
'create a new instance of Excel if there isn't one running.
oExcel = New Excel.Application ' #Comment: I get "new cannot be used on an
interface" on this one, how is this a interface ?
End Try
oBooks = oExcel.Workbooks
oBook = oBooks.Add
oSheet = CType(oBook.Worksheets(1), Excel.Worksheet) ' #Comment: Isn't this
sort of redundant, as the above CType statement ?
oSheet.Range("A1").Value = "Last Name"
oSheet.Range("B1").Value = "First Name"
oSheet.Range("A1:B1").Font.Bold = True
oSheet.Range("A2").Value = "Doe"
oSheet.Range("B2").Value = "John"
'Save the Workbook and quit Excel.
oBook.SaveAs("c:\temp\" & "Book1.xls")
oSheet = Nothing
oBook = Nothing
oBooks = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()
</CODE>
<DEBUG>
'DefaultDomain': Loaded
'c:\winnt\microsoft.net\framework\v1.1.4322\mscorlib.dll', No symbols
loaded.
'ExcelApp': Loaded 'C:\Documents and Settings\magnus\Mine Dokumenter\Visual
Studio Projects\ExcelApp\bin\ExcelApp.exe', Symbols loaded.
'ExcelApp.exe': Loaded
'c:\winnt\assembly\gac\system.windows.forms\1.0.5000.0__b77a5c561934e089\sys
tem.windows.forms.dll', No symbols loaded.
'ExcelApp.exe': Loaded
'c:\winnt\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll', No
symbols loaded.
'ExcelApp.exe': Loaded
'c:\winnt\assembly\gac\system.drawing\1.0.5000.0__b03f5f7f11d50a3a\system.dr
awing.dll', No symbols loaded.
'ExcelApp.exe': Loaded
'c:\winnt\assembly\gac\microsoft.visualbasic\7.0.5000.0__b03f5f7f11d50a3a\mi
crosoft.visualbasic.dll', No symbols loaded.
'ExcelApp.exe': Loaded 'c:\documents and settings\magnus\mine
dokumenter\visual studio projects\excelapp\bin\interop.excel.dll', No
symbols loaded.
An unhandled exception of type 'System.NullReferenceException' occurred in
ExcelApp.exe
Additional information: Object reference not set to an instance of an
object.
Unhandled Exception: System.NullReferenceException: Object reference not set
to an instance of an object.
at ExcelApp.Form1.Import_Click(Object sender, EventArgs e) in
C:\Documents and Settings\magnus\Mine Dokumenter\Visual Studio
Projects\ExcelApp\Form1.vb:line 81
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMetho
ds+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason,
Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at ExcelApp.Form1.Main() in C:\Documents and Settings\magnus\Mine
Dokumenter\Visual Studio Projects\ExcelApp\Form1.vb:line 1The program
'[1168] ExcelApp.exe' has exited with code 0 (0x0).
</DEBUG>