Excel to Powerpoint

Daddylouc

New Member
Joined
Nov 28, 2012
Messages
9
Hello,
I need some help as I'm still fairly new. I am looking for help in creating vba code that does these functions:
1. Insert a new blank slide at the end of a powerpoint file
2. Copy a range from the active excel worksheet (the range has some charts and a table)
3. Paste that range as a metafile into the newly created slide in powerpoint
4. Resize the metafile to fit the page
Note: I want to add this sub routine to a loop I've already created that refreshes the data and charts on the excel worksheet... the code needs to add a new slide to the end of the powerpoint file.

Appreciate any help!

I have been able to muster up/create this partially functioning script from several sources, but it's not doing those four steps.

Sub Powerpoint()
Dim PPPres As Object 'PowerPoint.Presentation
Dim PPSlide As Object 'PowerPoint.Slide
Dim PicCount As Long
Dim xSize As Double
Dim ySize As Double
On Error Resume Next

' CHECK TO SEE IF POWERPOINT FILE IS READY
Set PPApp = GetObject(, "PowerPoint.Application")
If PPApp Is Nothing Then ' PowerPoint is not running, notify and cancel
MsgBox "No Powerpoint session open. Please open a Powerpoint file first."
Exit Sub
End If
On Error GoTo 0

Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = 1 'ppViewSlide
Set PPSlide = PPPres.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
AppActivate "Microsoft Powerpoint" 'temp command
PPPres.Slides(1).Copy
PPPres.Slides.Paste (PPPres.Slides.Count + 1)


AppActivate "Microsoft Excel" 'temp command
Range("A1:V71").Select
Selection.Copy

AppActivate "Microsoft Powerpoint" 'temp command
PPSlide.Shapes.PasteSpecial DataType:=2, _
Link:=0

' Align the pasted range
PicCount = PPApp.ActiveWindow.Selection.SlideRange.Shapes.Count
With PPApp.ActiveWindow.Selection.SlideRange.Shapes(PicCount)
.Select
.LockAspectRatio = 0 'msoFalse
.Top = 12
.left = 12


xSize = 690 / .Width
ySize = 408 / .Height

If ySize <= xSize Then
'use y
.ScaleHeight ySize, 0 'msoFalse
.ScaleWidth ySize, 0 'msoFalse
Else
'use x
.ScaleHeight xSize, 0 'msoFalse
.ScaleWidth xSize, 0 'msoFalse
End If
.LockAspectRatio = -1 'msoTrue
End With
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
PPApp.ActiveWindow.ViewType = 9 'ppViewNormal
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing

AppActivate "Microsoft Excel"
Beep
End Sub


- Lou
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Thanks Andrew. I created the AppActivates as temporary commands because I wanted to see what was happening as I step through the routine. I'll remove those later.

Thanks for the link- I'll check it out
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,412
Members
448,960
Latest member
AKSMITH

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