0

I want to resize a Chart object. I am creating a graph from a set of data in Excel and inserting the graph in a Word doc via VBA.

I tried to use .Width property from the ChartObjects object but I couldn't extend this to chart. ( I got an application error with ws1.ChartObjects.)

Sub CPU_Top_10_Chart()

Dim wdApp   As Word.Application
Dim wdDoc   As Word.Document
Dim cht     As Chart
Dim ws1     As Worksheet

 Set wdApp = CreateObject("Word.Application")
 Set wdDoc = wdApp.Documents.Add("C:\...\chart_test.docx")

 Set cht = Charts.Add
 Set ws1 = ActiveWorkbook.Sheets("Sheet1")

 With cht

        .SetSourceData Source:=ws1.Range("A2:C12")
        .ChartType = xlColumnClustered

End With

cht.CopyPicture
wdDoc.Bookmarks("insert_chart").Range.Paste
End Sub
4
  • Seems, you're trying to paste image into word document instead of linked chart. Commented May 4, 2016 at 19:10
  • Yes, I am trying to do this with VBA. But I want to resize the Chart. Commented May 4, 2016 at 19:15
  • Inside word document or sheet? Commented May 4, 2016 at 19:17
  • I am trying to insert the chart to a Word doc. Commented May 4, 2016 at 19:24

2 Answers 2

2

You could call "Worksheet.Shapes.AddChart" to create the chart and set the size:

With ActiveSheet.Shapes.AddChart(xlColumnClustered, Width:=100, Height:=100)
  With .Chart
    .SetSourceData ws1.Range("A2:C12")
  End With
  .CopyPicture
End With
Sign up to request clarification or add additional context in comments.

3 Comments

So don't use Chart and just try it with Shapes object?
A Chart is a Shape and some properties like the height and width are only available on the Shape.
The chart is contained within a special shape called a chartobject. The chartobject has all the properties of a shape. You can access the chartobject using chart.parent.
0

This is what I added

Set cht = ws1.Shapes.AddChart(xlColumnClustered, Width:=300, Height:=300).Chart

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.