Apply one macro to specific chart on several slides

alonso9122

New Member
Joined
Aug 10, 2018
Messages
3
Dear Community,

On the last days I have tried to develop the following:

I have a PPT presentation with a specific amount of slides. Starting from the second slide I have pasted excel tables directly linked to the file (paste special). Sometimes I have been facing the issue that after updating the links when I open the PPT presentation, the tables appear with a different size and position.

To get rid of this, I would like to have a macro that allows me to resize and reposition all these charts to the desired values.

I found the following resizing/repositioning part:

Sub Adjustment()

With ActiveWindow.Selection.ShapeRange
.LockAspectRatio = msoFalse
.Height = 168
.Width = 992
.Left = 39
.Top = 157
End With

End Sub

It works well but as you realize it only works after clicking the specific chart and then running the macro.

My ideal would be:

1. Loops through each slide (starting from the second to the end)
2. On each slide, selects this only shape/chart (as on each slide I also have some boxes, aside from the excel table) and applies those same properties

I tried my best but hit a wall. I would really appreciate your support!

Thank you very much in advance!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Here's a start...

Code:
Dim sl as Slide
Dim sh as Shape
Const t = 157
Const l = 39
Const w = 992
Const h = 168
dim y as long
y = You'll need to figure out the "type" value for the charts 
With ActiveWindow
    With .Presentation
        For Each sl In .Slides
            sl.Select
            DoEvents
            If sl.Shapes.Count > 0 Then
                    For Each sh In sl.Shapes
                         if sh.Type = y Then
                           sh.Top = t
                           sh.Left = l
                           sh.Width = w
                           sh.Height = h
                         end if
                     next
              end if
         next
      end with
end with
 
Upvote 0
Thank you very much for your quick reply! Really helpful :) It work with the value type 10 for a range.

One additional question: In case I would have 2 range types on one slide, but I would always like to format only one of them (as the other is just a text im bringing from the excel sheet), what could it be a good solution?

Is it possible to say, to not run slide by slide but then say for instance:

For object 1 to 10, add these properties. Or is it the case PPT only allows me to go slide by slide?

Thank you!
 
Upvote 0
Each shape that you add to a slide can have an "Alternative Text" property (right click, format Shape, Alt Text).
You could add some standard text to those shapes you don't want to adjust.

then
Code:
Dim txtMask as string
txtMask ="Skip Me"
...



If InStr(sh.AlternativeText, txtMask) = 0 Then
.. do the adjustments
end if
 
Upvote 0
Thank you very much for your reply! Worked it with your advise and turned out pretty well :) Also for not telling me the 100% exact answer so I can properly learn.
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top