Click here to Skip to main content
16,010,491 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

I am new to this site. I have a question regarding editing graphs using vb.net code. I have a graph named 'ChartModel', I use a code to edit the Chart Title, but it gives me an error that says invalid index. The title will be concatenated though a combo box from the GUI. I searched the site for articles regarding editing graph using vb.net, but I can't find any. I just found articles on how to create graphs. Currently here is my code:

VB
Public Shared Sub FormatCharts(ByVal WB As Excel.Workbook)
        Dim WS As Excel.Worksheet = WB.Sheets(4)
        Dim oChart As Excel.Chart
        Dim xlChart As Excel.ChartObjects = WS.ChartObjects
        Dim myChart As Excel.ChartObject = WB.Charts(1)'this is where the error occurs. I also used WB.Charts("ChartModel")
        oChart = myChart.Chart

        With oChart
            .HasTitle = True
            .Activate()
            .Select()
            If ReportControlForm.txtDupOptModel.Text <> String.Empty Then
                .ChartTitle.Text = "Device Count by " & ReportControlForm.txtDupOptModel.Text
            End If

        End With

    End Sub


I can't figure out on how to point it to the correct graph. Any help is greatly appreciated.
Posted
Comments
Slacker007 12-Sep-11 6:03am    
If you debug your code and step through it line by line where exactly is it throwing the error?
Franco Cipriano 13-Sep-11 19:13pm    
its in this line Dim myChart As Excel.ChartObject = WB.Charts(1)

Thanks,

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900