Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Chart problem - works in VBA, but not VB.Net

The following code was ported directly from some older VBA code that we
have. The VBA code works fine, but when we run it from VB.Net we get
an exception. What might be the problem?

The VB.Net code is simply trying to add a data series to a chart (using
Excel 2003). This is the code:

----

Dim worksheet as Excel.Worksheet
Dim xvalues, yvalues as Excel.Range

..
..
..

' Create new chart object embedded in the worksheet
Dim chart As Excel.Chart = CType(worksheet.ChartObjects,
Excel.ChartObjects).Add(400, 0, 640, 480).Chart
chart.ChartType = Excel.XlChartType.xlXYScatterLines

' add data series to the chart
CType(chart.SeriesCollection,
Excel.SeriesCollection).Add(Source:=application.Un ion(xvalues,yvalues))

----

When the final line of code is executed, we get the following error:

System.InvalidCastException
OleAut reported a type mismatch.
Stack trace:
at Microsoft.Win32.OAVariantLib.ChangeTypeEx(Variant source, Int32
lcid, Int32 cvType, Int16 flags)
at Microsoft.Win32.OAVariantLib.ChangeType(Variant source, Type
targetClass, Int16 options, CultureInfo culture)
at System.OleAutBinder.ChangeType(Object value, Type type, CultureInfo
cultureInfo)
at System.RuntimeType.ForwardCallToInvokeMember(Strin g memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at Microsoft.Office.Interop.Excel.SeriesCollection.Ad d(Object Source,
XlRowCol Rowcol, Object SeriesLabels, Object CategoryLabels, Object
Replace)


Oddly enough, the chart *is* created and the data series appears to
have been added properly. So what can we do to prevent this exception
from being thrown?

Some other relevant information... We're working in VB.Net 2003. The
interop library we're using is the Microsoft Excel 11.0 Object Library.

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
Chart issue--works in 2007, not in 2010 tmidgett Charts and Charting in Excel 0 February 8th 11 05:43 PM
Counting text problem - formula works initially Anne P Excel Worksheet Functions 3 July 8th 09 06:40 PM
Chart slice colours....almost works Naz Excel Programming 3 September 8th 06 03:46 PM
Problem with HLookup - Sometimes works, sometimes blank. Regnab Excel Discussion (Misc queries) 3 May 22nd 06 04:09 AM
VBA problem, works fine as formula but not in VBA Xlund Excel Programming 4 April 13th 04 10:57 AM


All times are GMT +1. The time now is 09:42 AM.

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"