Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I modify excel chart Title

Status
Not open for further replies.

TekMem

Programmer
Jul 23, 2004
98
0
0
CA
Hi,

I need help to modify title for existing chart in my excel.
I can open my excel...populate data in cells but I am not sure how can I modity TITLE for the existing chart in that excel.

Thanks.
 
Thanks PRPhx for response.
There is no problem in adding new charts but cannot modify chart title for existing chart. I am unable to write codes to open chart and modify its title(I am not declaring chart objects properly so that it can open existing chart).
 
code?

-I hate Microsoft!
-Forever and always forward.
 
Dim oXL As Application
Dim oWB As Workbook
Dim oSheet As Worksheet
Dim oRng As Range
Dim ochart As Microsoft.Office.Interop.Excel.Chart
'Dim objExcel As New Microsoft.Office.Interop.Excel.Application
Try
' Start Excel and get Application object.
oXL = New Microsoft.Office.Interop.Excel.Application
oWB = oXL.Workbooks.Open("c:\\THU\NDP\NDP.xls")
oSheet = oWB.Worksheets(1)

oXL.Visible = True
' Get a new workbook.

oSheet.Cells(5, 1).Value = "Sr #"
oSheet.Cells(5, 2).Value = "Project Name"

With oSheet.Range("A5", "H5")
.Font.Bold = True
.VerticalAlignment = XlVAlign.xlVAlignCenter
.Interior.ColorIndex = 6
End With
oSheet = oWB.Worksheets(3)
' ochart = oSheet.ChartObjects(1)
ochart = oWB.ActiveChart
ochart.HasTitle = True

Catch ex As System.Runtime.InteropServices.COMException
MessageBox.Show("Error accessing Excel: " + ex.ToString())

Catch ex As Exception
MessageBox.Show("Error: " + ex.ToString())
Finally
oRng = Nothing
oXL.DisplayAlerts = False

oSheet = Nothing
oWB.Close()
oWB = Nothing
oXL.Quit()
oXL = Nothing
GC.Collect()

End Try
 
Did you even look at the code in the link I gave you?????
Take a look at it and use the info within it to add a chart object and then modify the title.
 
The way you are doing it this should work.
Code:
ochart.ChartTitle.Characters.Text = "NewChartName"
You need to place it any time after.
Code:
 ochart = oWB.ActiveChart
ochart.HasTitle = True

-I hate Microsoft!
-Forever and always forward.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top