Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default COMException With Microsoft.Office.Interop.Excel

I'm trying to insert an image into an Excel cell. Please see the following
code. Does
anybody have a way to fix this "COMException"? I thought setting the new
reference in Visual Studio
took care of "wrapping" COM objects for use with .Net?

I can't even get the workbook object established let alone see if the rest
of this works!


Imports Microsoft.Office.Interop.Excel


Private Sub Spreadsheet()
Dim i As System.Drawing.Image
Dim xl As New Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
Dim range As Microsoft.Office.Interop.Excel.Range
xl.Workbooks.Add(wb) <--------------------------------------- Error
Location
wb.Sheets.Add(ws)
range = ws.Range(5, 5)
i =
System.Drawing.Image.FromFile("C:\inetpub\wwwroot\ capitalprojects\Images\GSImgtmpED6.png")
range.Select()
ws.PasteSpecial(i)
ws.SaveAs("C:\test.xls")
xl.Quit()
i.Dispose()
End Sub

An unhandled exception of type 'System.Runtime.InteropServices.COMException'
occurred in Scratch.exe

Additional information: Exception from HRESULT: 0x800A03EC.

Any help greatly appreciated.

Frank Fox
Hendersonville, Tennessee

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default COMException With Microsoft.Office.Interop.Excel

wb is an object variabele which gets its value by 'Set', so if you try:

Set wb = xl.Workbooks.Add

maybe that error will be fixed.



"frankvfox" schreef in bericht
...
I'm trying to insert an image into an Excel cell. Please see the following
code. Does
anybody have a way to fix this "COMException"? I thought setting the new
reference in Visual Studio
took care of "wrapping" COM objects for use with .Net?

I can't even get the workbook object established let alone see if the rest
of this works!


Imports Microsoft.Office.Interop.Excel


Private Sub Spreadsheet()
Dim i As System.Drawing.Image
Dim xl As New Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
Dim range As Microsoft.Office.Interop.Excel.Range
xl.Workbooks.Add(wb) <--------------------------------------- Error
Location
wb.Sheets.Add(ws)
range = ws.Range(5, 5)
i =
System.Drawing.Image.FromFile("C:\inetpub\wwwroot\ capitalprojects\Images\GSImgtmpED6.png")
range.Select()
ws.PasteSpecial(i)
ws.SaveAs("C:\test.xls")
xl.Quit()
i.Dispose()
End Sub

An unhandled exception of type
'System.Runtime.InteropServices.COMException'
occurred in Scratch.exe

Additional information: Exception from HRESULT: 0x800A03EC.

Any help greatly appreciated.

Frank Fox
Hendersonville, Tennessee



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default COMException With Microsoft.Office.Interop.Excel

And two more things...

'range' is a reserved keyword in Excel-Vba, so better replace that name by
'rng' or 'myRange' - whatever.
Then, because it's an object too, you use: Set myRange = ws.Range(5,5)



"frankvfox" schreef in bericht
...
I'm trying to insert an image into an Excel cell. Please see the following
code. Does
anybody have a way to fix this "COMException"? I thought setting the new
reference in Visual Studio
took care of "wrapping" COM objects for use with .Net?

I can't even get the workbook object established let alone see if the rest
of this works!


Imports Microsoft.Office.Interop.Excel


Private Sub Spreadsheet()
Dim i As System.Drawing.Image
Dim xl As New Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
Dim range As Microsoft.Office.Interop.Excel.Range
xl.Workbooks.Add(wb) <--------------------------------------- Error
Location
wb.Sheets.Add(ws)
range = ws.Range(5, 5)
i =
System.Drawing.Image.FromFile("C:\inetpub\wwwroot\ capitalprojects\Images\GSImgtmpED6.png")
range.Select()
ws.PasteSpecial(i)
ws.SaveAs("C:\test.xls")
xl.Quit()
i.Dispose()
End Sub

An unhandled exception of type
'System.Runtime.InteropServices.COMException'
occurred in Scratch.exe

Additional information: Exception from HRESULT: 0x800A03EC.

Any help greatly appreciated.

Frank Fox
Hendersonville, Tennessee



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default COMException With Microsoft.Office.Interop.Excel

Frank
Unless .Net is that different to the original VB/VBA, there no Excel to work
with, only dimmed variables.

You will need to create an instance of Excel to work with:
Set xl=New Excel.Application
set wb=xl.Workbooks.Add

etc...

NickHK

"frankvfox" wrote in message
...
I'm trying to insert an image into an Excel cell. Please see the following
code. Does
anybody have a way to fix this "COMException"? I thought setting the new
reference in Visual Studio
took care of "wrapping" COM objects for use with .Net?

I can't even get the workbook object established let alone see if the rest
of this works!


Imports Microsoft.Office.Interop.Excel


Private Sub Spreadsheet()
Dim i As System.Drawing.Image
Dim xl As New Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
Dim range As Microsoft.Office.Interop.Excel.Range
xl.Workbooks.Add(wb) <---------------------------------------

Error
Location
wb.Sheets.Add(ws)
range = ws.Range(5, 5)
i =

System.Drawing.Image.FromFile("C:\inetpub\wwwroot\ capitalprojects\Images\GSI
mgtmpED6.png")
range.Select()
ws.PasteSpecial(i)
ws.SaveAs("C:\test.xls")
xl.Quit()
i.Dispose()
End Sub

An unhandled exception of type

'System.Runtime.InteropServices.COMException'
occurred in Scratch.exe

Additional information: Exception from HRESULT: 0x800A03EC.

Any help greatly appreciated.

Frank Fox
Hendersonville, Tennessee



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default COMException With Microsoft.Office.Interop.Excel

Thanks to both moon and NickHK for their concern and suggestions. I
appreciate you took the time to try to help me.

It appears I have inadvertently posted to the Excel VBA track and not to the
VB.Net Excel Interop group. My apologies.

I'm using VB.Net 2003 and banging my head against the wall.

moon ... the Set keyword is no longer used in a standalone expression in
VB.Net in a fashion similar to the old Let expression in original Basic. Set
is implied if you are setting one object to another (when both have been
previously defined as objects).

NickHK ... the "Dim xl As New Microsoft.Office.Interop.Excel.Application"
line is a combination dimensioning and instancing expression which creates
the Excel Application in place of the older Set expression you use in VBA.

I think I've got problems here which you would never encounter with embedded
VBA. Splicing COM objects into a .Net application is proving to be a
formidable task.

Again, thanks for your input. You've alerted me to my misdirection!

Off to the other track.

Frank
__________________________________________________ __

Frank
Unless .Net is that different to the original VB/VBA, there no Excel to work
with, only dimmed variables.

You will need to create an instance of Excel to work with:
Set xl=New Excel.Application
set wb=xl.Workbooks.Add

etc...

NickHK
__________________________________________________ __

wb is an object variabele which gets its value by 'Set', so if you try:

Set wb = xl.Workbooks.Add

maybe that error will be fixed.

moon
__________________________________________________ __

I'm trying to insert an image into an Excel cell. Please see the following
code. Does
anybody have a way to fix this "COMException"? I thought setting the new
reference in Visual Studio
took care of "wrapping" COM objects for use with .Net?

I can't even get the workbook object established let alone see if the rest
of this works!


Imports Microsoft.Office.Interop.Excel


Private Sub Spreadsheet()
Dim i As System.Drawing.Image
Dim xl As New Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
Dim range As Microsoft.Office.Interop.Excel.Range
xl.Workbooks.Add(wb) <---------------------------------------
Error
Location
wb.Sheets.Add(ws)
range = ws.Range(5, 5)
i =

System.Drawing.Image.FromFile("C:\inetpub\wwwroot\ capitalprojects\Images\GSI
mgtmpED6.png")
range.Select()
ws.PasteSpecial(i)
ws.SaveAs("C:\test.xls")
xl.Quit()
i.Dispose()
End Sub

An unhandled exception of type
'System.Runtime.InteropServices.COMException'
occurred in Scratch.exe

Additional information: Exception from HRESULT: 0x800A03EC.

Any help greatly appreciated.

Frank Fox
Hendersonville, Tennessee


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Microsoft.Office.Interop.Excel when exporting from another program Colin Excel Discussion (Misc queries) 0 January 2nd 09 06:08 AM
Microsoft.Office.Interop.Excel SaveAs error when clicking no or ca NeedsExcelAssistance Excel Programming 0 July 14th 06 02:50 PM
Exception from HRESULT: 0x800A03EC. at Microsoft.Office.Interop.Excel.WorkbookClass.get_VBProject() [email protected] Excel Programming 0 April 11th 06 04:40 PM
Deployment of Microsoft Office Xp Primary Interop Assembly [email protected] Excel Programming 0 October 10th 05 01:36 PM
Calling from C#.Net App Office._CommandBarButton.Execute() method in Excel 2003 throws a COMException Jacek Excel Programming 1 December 21st 03 03:48 PM


All times are GMT +1. The time now is 02:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"