Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Can anybody see what I have left out? The following code extracts succeed in successfully placing a ChartObject on the right Worksheet, which appears to have picked up the data series and, if the First Failure is commented out, the correct Chart type. However, nothing I have managed to do allows me to set the Chart Title or to make the beastly thing actually appear!
 
xlApp is the Excel application
xlWB is the Excel Workbook
xlWS has been declared as Object
xlChartSheet has been declared as object and set as the active sheet
oRange has been declared as Object
 
sCalcSheetName, sRowAddress, sLeftRowCell, sRightRowCell, sRowName have been declared as a string
 
Relevant lines of code are as follows:

xlChartSheet.ChartObjects.Add(Left:=100, Width:=375, Top:=75, Height:=225)

 
(Commented out) Code below reads the data series of the Chart, one series at a time, finds the Worksheet on which the row appears, reads its address, gets the left and right cells of the range, creates a Range object which is added to the Charts SeriesCollection, as follows
 
While sContent.Length is greater than 0
 
...
 
xlApp.Goto(sRowName)
xlWS = xlWB.ActiveSheet
sCalcSheetName = xlWS.Name
xlRange = xlWS.Range(sRowName)
sRowAddress = xlRange.Address
sLeftRowCell = xxx (string to the left of the colon)
sRightRowCell = yyy (string to the right of the colon)
 
oRange = xlWS.Range(sLeftRowCell, sRightRowCell)
 
xlChartSheet.ChartObjects(1).Chart.SeriesCollection.Add(oRange)
 
...
 
End While

 
(Question) All of which seems to be working, but it never reaches either of the two snippets below; Can anyone spot what have I left out?
 
(First failure) With the following, throws up Unable to set the HasAxis property of the Chart Class
 
With xlChartSheet.ChartObjects(1).Chart
.HasAxis(1, 1) = False
.HasAxis(2, 1) = False
End With

 
(Second failure) Without the above, throws up Unable to set the HasTitle property of the Chart Class
 
With xlChartSheet.ChartObjects(1).Chart
.ChartType = 4
.HasLegend = False
.HasTitle = True
End With

 

(NB) xlConstants in the two snippets above have been replaced with their numeric values
...
Posted 17-May-10 6:59am
Edited 17-May-10 8:25am
432.2K
v2
Comments
losmac at 20-Jan-11 16:38pm
   
Show me all code lines and tell me: are you using OLE automation or InteropServices?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 375
1 Gihan Liyanage 338
2 Vinay Mistry 160
3 Sergey Alexandrovich Kryukov 130
4 syed shanu 125
0 Sergey Alexandrovich Kryukov 9,021
1 OriginalGriff 7,941
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 17 May 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100