Need help controlling PowerPoint from Excel

Dave L

Board Regular
Joined
Jun 19, 2003
Messages
87
I am trying to automate the transfer of a range of cells to PowerPoint just by clicking a button on the Excel sheet. I have the code below which works great.

Sub CreatePowerPointFromChart()
Const ppLayoutBlank As Integer = 12
Const ppWindowMaximized As Integer = 3
Dim PPTApp As Object
Dim Pres1 As Object
Dim Slide1 As Object

Set PPTApp = CreateObject("PowerPoint.Application")

With PPTApp
.Visible = True
.WindowState = ppWindowMaximized
Set Pres1 = PPTApp.Presentations.Add
End With

Set Slide1 = Pres1.Slides.Add(1, ppLayoutBlank)

' Copy and paste selected range
Range("A1:M40").CopyPicture
PPTApp.ActiveWindow.View.Paste

End Sub

The problem is that the contents of the Excel sheet that are being copied need to be pasted into an 8.5 x 11 PowerPoint slide, not the default 7.5 x 10. I recorded a macro in PowerPoint to change the Page Setup and got the following:

Sub Macro1()

With ActivePresentation.PageSetup
.SlideSize = ppSlideSizeCustom
.SlideWidth = 792
.SlideHeight = 612
.FirstSlideNumber = 1
.SlideOrientation = msoOrientationHorizontal
.NotesOrientation = msoOrientationVertical
End With
End Sub

However, if I put that into my code above I get error messages. This Excel file will be used by clients who will create charts with the Excel file and may want to transfer them to PowerPoint, so I would like this one Excel macro to handle everything.

Any ideas how I can control the page setup in PowerPoint from Excel?

Thanks,

Dave
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
The principle is that if we are manipulating an external application with Excel code we need to explicitly include the Application Object.

I have not used PowerPoint this way, but from Excel your PowerPoint macro will probably translate as :-
Code:
With PPTapp.ActivePresentation.PageSetup 
    .SlideSize = ppSlideSizeCustom 
    .SlideWidth = 792 
    .SlideHeight = 612 
    .FirstSlideNumber = 1 
    .SlideOrientation = msoOrientationHorizontal 
    .NotesOrientation = msoOrientationVertical 
End With
 
Upvote 0

Forum statistics

Threads
1,214,627
Messages
6,120,610
Members
448,973
Latest member
ChristineC

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