Sunday, July 20, 2008

Adding Default Chart to a Sheet using Excel VBA

Adding Default Chart to a Sheet using Excel VBA

Excel has default chart (might be bar chart). The following code just creates the same using available data

Excel ChartWizard Output

Sub Add_Default_Chart_2003()

Dim oChts As ChartObjects '* Chart Object Collection

Dim oCht As ChartObject '* Chart Object

Dim oWS As Worksheet '* WorkSheet

On Error GoTo Err_Chart

oWS = ActiveSheet

oChts = oWS.ChartObjects

oCht = oChts.Add(100, 100, 150, 150)

oCht.Chart.ChartWizard(oWS.Range("B1", "C4"))

' Release/Dispose Objects

If Not oCht Is Nothing Then oCht = Nothing

If Not oChts Is Nothing Then oChts = Nothing

If Not oWS Is Nothing Then oWS = Nothing

Exit Sub


MsgBox(Err.Number & " - " & Err.Description)


Resume Next

End Sub

No comments:

Post a Comment

Share on Facebook
Related Posts Plugin for WordPress, Blogger...

Visual Basic for Applications (VBA) Forum (recent threads)

CodeKeep VBA Feed

Visual Studio Tools for Office Forum (recent threads)

Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.

Office Business Applications (OBA) Team Blog

MSDN Code Gallery Published Resources For Tag VSTO Google Group