Sub ExportPPTRoutine(PicSize As Integer)
'export selected range to an open PPT slide, as a metafile
'Picsize 1 = full size, 4 = 4up
Dim PPApp As Object 'PowerPoint.Application
Dim PPPres As Object 'PowerPoint.Presentation
Dim PPSlide As Object 'PowerPoint.Slide
Dim PicCount As Long
Dim xSize As Double
Dim ySize As Double
' Make sure a range or chart is selected
If TypeName(Selection) <> "Range" And TypeName(Selection) <> "ChartArea" Then
MsgBox "Please select a worksheet range/chart and try again.", vbExclamation, _
"No Range/Chart Selected"
Else
' Reference instance of PowerPoint
On Error Resume Next
' Check whether PowerPoint is running
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 PPT file first."
Exit Sub
End If
On Error GoTo 0
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = 1 'ppViewSlide
' Reference active slide
Set PPSlide = PPPres.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
' Copy and Pastespecial the range
Selection.Copy
'PPSlide.Shapes.PasteSpecial DataType:=ppPasteEnhancedMetafile, _
Link:=msoFalse
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 = 78
.Left = 12
Select Case PicSize
Case 1 'full size
xSize = 690 / .Width
ySize = 408 / .Height
Case 4 '4up size
xSize = 352 / .Width
ySize = 202 / .Height
End Select
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
' Clean up
PPApp.ActiveWindow.ViewType = 9 'ppViewNormal
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End If
Beep
End Sub