vba to centre a shape on a powerpoint slide

cjcass

Well-known Member
Joined
Oct 27, 2011
Messages
683
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have the following code that selects an area in Excel then pastes it into powerpoint.


'Transition3
Sheet76.Select

Dim shp As Object
Dim sld As Object
Dim eff As Object


Const msoAnimEffectFade As Long = 10
Const msoAnimTriggerWithPrevious As Long = 2

Set PPApp = GetObject(, "Powerpoint.Application")
Set PPPres = PPApp.ActivePresentation


ActiveSheet.Range("H113").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture 'excel range to be pasted
Set sld = PPPres.Slides("Transition3")
Set shp = sld.Shapes.Paste.Item(1)


'add fade effect to shape
Set eff = sld.TimeLine.MainSequence.AddEffect _
(Shape:=shp, effectid:=msoAnimEffectFade, Trigger:=msoAnimTriggerWithPrevious)

eff.Timing.Duration = 0.5
eff.Timing.TriggerDelayTime = 0

With shp
.LockAspectRatio = msoTrue
.ScaleHeight 0.47, msoTrue
.Left = 27
.Top = 56
.ZOrder msoSendToBack

End With


How do I change the .Left and .Top positioning so the shape is centred on the slide (after it has been re-scaled)..?

Hope you can help, many thanks :)
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
This should work:

Code:
With shp
        .LockAspectRatio = msoTrue
        .ScaleHeight 0.47, msoTrue
        sngDefaultSlideWidth = PPPres.PageSetup.SlideWidth
        sngDefaultSlideHeight = PPPres.PageSetup.SlideHeight
        .Left = (sngDefaultSlideWidth - .Width) / 2
        .Top = (sngDefaultSlideHeight - .Height) / 2
        .ZOrder msoSendToBack
End With
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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