logo
search
VBA & Macro Problems

How to Change PowerPoint Chart Size and Position using VBA

Chanuka GeekiyanageChanuka Geekiyanage Oct 21, 2026 868 views

Question details

The user needs to properly resize and center a chart on a PowerPoint slide using VBA without triggering layout errors.

How to Change PowerPoint Chart Size and Position with VBA
Product
PowerPoint
Device & OS
not provided
Scenario
Automating presentation layouts using VBA to adjust chart dimensions and center them automatically.
Observed behavior
Using the ChartArea.Height property resizes the internal plot area rather than the actual chart object container, resulting in visual errors and an inability to correctly scale the chart.
Before you start

Ensure your presentation is open, the Developer tab is enabled to access the VBA editor, and you know the name or index of the chart shape you intend to modify.

Solution 1Recommended

Use the Shape Object to Resize and Center the Chart

Target the parent Shape object containing the chart to properly alter its outer dimensions and adjust its position on the slide.

When attempting to resize a chart in PowerPoint via VBA, modifying the ChartArea properties will only affect the inner boundaries of the chart inside its container. To scale the entire chart object and avoid structural errors, you must manipulate the Shape object itself.

To perfectly center the chart, calculate the middle of the slide by subtracting the chart's width and height from the slide's total width and height, then dividing the result by two.

1
Open the VBA Editor

Press ALT + F11 in PowerPoint to open the VBA Editor, and insert or select the module where you are writing your formatting macro.

2
Assign the Shape Variable

Set a variable for your chart's shape (e.g., Set shp = myPresentation.Slides(1).Shapes("Chart 1")) to directly target the object container.

3
Resize the Chart

Adjust the overall size of the chart by changing the shape's properties, for example: shp.Height = 432 and shp.Width = 600.

4
Center the Chart Vertically

Apply the centering formula to the Top property: shp.Top = (myPresentation.PageSetup.SlideHeight - shp.Height) / 2.

5
Center the Chart Horizontally

Apply the centering formula to the Left property: shp.Left = (myPresentation.PageSetup.SlideWidth - shp.Width) / 2.

Use the Shape Object to Resize and Center the Chart
Resetting Layout Placeholders: If you are working with a chart inserted into a slide layout placeholder and the placeholder was previously resized manually, the VBA changes might not display correctly. Return to the normal slide view and select Home > Reset to refresh the layout.
Efficient Presentation Automation

Automate Presentations with WPS Presentation

WPS Office provides robust VBA and Macro support in its premium versions, allowing you to seamlessly run presentation scripts to resize, position, and format your charts without layout errors.

  1. 1. Download and Install WPS Office: Download WPS Office from the official website and open WPS Presentation.
  2. 2. Open Your Macro-Enabled File: Open your .pptm presentation file and navigate to the Developer tab on the ribbon.
  3. 3. Run Chart VBA Macros: Click on 'Macros' to access the VBA editor, where you can paste and execute your chart resizing and centering scripts flawlessly.
Fully compatible with Microsoft PowerPoint formats (.ppt, .pptx, .pptm).Powerful integrated VBA environment for automating chart formatting and alignment.Lightweight interface ensuring complex macros execute quickly and smoothly.
QA img-9

Frequently Asked Questions

Why does using ChartArea.Height cause errors in my PowerPoint macro?

The ChartArea property refers exclusively to the internal plotted area of the chart. Modifying its size independently of its parent container (the Shape object) causes the internal layout to break or throw out-of-bounds errors. You should always use the Shape object's Height and Width properties instead.

How do I align a chart exactly in the middle of a PowerPoint slide using VBA?

To center a chart, you need to use the slide's dimensions and the chart's dimensions. Set the Shape.Top property to '(SlideHeight - Shape.Height) / 2' and the Shape.Left property to '(SlideWidth - Shape.Width) / 2'.

What should I do if my VBA code runs but the chart doesn't look updated?

If the chart is bound to a slide layout placeholder that has been manually adjusted, the macro's size changes may conflict with the layout rules. Go to the Home tab and click 'Reset' to clear manual formatting and allow the macro's properties to take effect.