Excel VBA to Change PowerPoint Slide Size

paveil

New Member
Joined
Sep 4, 2019
Messages
2
Hi All,

I have some code that takes a range from excel, creates a PowerPoint presentation and paste's the range from excel as a picture in PowerPoint - which works. The issue I have now is that PowerPoint opens in Widescreen format and I wanted some code for excel to change the slide size to standard.

I've played around with different code, but also receive errors (various errors). Does anyone have any ideas?

Code is below:

Dim rng As Range
Dim rng1 As Range
Dim rng2 As Range
Dim PowerPointApp As Object
Dim myPresentation As Object
Dim mySlide As Object
Dim mySlide1 As Object
Dim myShape As Object
Dim myShape1 As Object
Dim myShape2 As Object


'Create an Instance of PowerPoint
On Error Resume Next

'Is PowerPoint already opened?
Set PowerPointApp = GetObject(class:="PowerPoint.Application")

'Clear the error between errors
Err.Clear


'If PowerPoint is not already open then open PowerPoint
If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(class:="PowerPoint.Application")

'Handle if the PowerPoint Application is not found
If Err.Number = 429 Then
MsgBox "PowerPoint could not be found, aborting."
Exit Sub
End If


On Error GoTo 0


'Optimize Code
Application.ScreenUpdating = False

'Create a New Presentation
Set myPresentation = PowerPointApp.Presentations.Add


'Add a slide to the Presentation
Set mySlide = myPresentation.Slides.Add(1, 12) '12 = ppLayoutBlank


'Optimize Code
Application.ScreenUpdating = False

'Copy Range from Excel
Set rng = ThisWorkbook.ActiveSheet.Range("A8:Y122")


'Copy Excel Range
rng.Copy


'Paste to PowerPoint and position

Application.ScreenUpdating = True

mySlide.Shapes.PasteSpecial DataType:=1

Set myShape = mySlide.Shapes(mySlide.Shapes.Count)

'Set Position:
myShape.Left = 0
myShape.Top = 33


' Set Size:
myShape.Height = 400
myShape.Width = 700


' - - - - -


Application.ScreenUpdating = False
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi,

Use: myPresentation.PageSetup.SlideSize = 1 'ppSlideSizeOnScreen = 1

Regards
 
Upvote 0
Absolutely brilliant - thank you. I had tried the same thing, but was putting ppSlideSizeOnScreen instead of '1'. :-)
 
Upvote 0
You are welcome, and welcome to the MrExcel board! :)
 
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,135
Members
453,021
Latest member
Justyna P

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