Solved

How to change chart titles and axis VB.Net Excel Charting

Posted on 2012-03-28
2
656 Views
Last Modified: 2012-03-28
I have created a simple chart in a worksheet and need to change the default axis titles but have a problem with syntax.
	
With objChart

   .Name = "Turnover Chart"
   .SetSourceData(Source:=objRange1, PlotBy:=Excel.XlRowCol.xlColumns)
   .ChartType = Excel.XlChartType.xlCylinderColStacked
   .Location(Where:=Excel.XlChartLocation.xlLocationAsObject, Name:="Chart")

   ' THE NEXT LINE THROWS AN EXCEPTION
   objAxis = CType(.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary), Excel.Axis)

   With objAxis
       .HasTitle = True
       .AxisTitle.Text = "Sales"
   End With

End With

Open in new window

0
Comment
Question by:TeDeSm
2 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 37775853
I think the Location line is the problem as it actually returns a new reference to the chart object, so:
With objChart

   .Name = "Turnover Chart"
   .SetSourceData(Source:=objRange1, PlotBy:=Excel.XlRowCol.xlColumns)
   .ChartType = Excel.XlChartType.xlCylinderColStacked
End With
  objChart = objChart.Location(Where:=Excel.XlChartLocation.xlLocationAsObject, Name:="Chart")
With objChart
   ' THE NEXT LINE THROWS AN EXCEPTION
   objAxis = CType(.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary), Excel.Axis)

   With objAxis
       .HasTitle = True
       .AxisTitle.Text = "Sales"
   End With

End With

Open in new window

0
 

Author Closing Comment

by:TeDeSm
ID: 37776091
I had figured that I had lost the reference to the chart, just couldn't figure out where'

A spot on solution.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel Calculate Average - Grouped Values 7 23
Select Next Route by Time 4 20
If help 9 49
Formula Help 3 23
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question