OK, 2003. Good.
But I don't quite follow the logic here. Is there already a chart on the slide?
If you want to empty the content placeholder, you can delete it then reapply the
current layout. That will give you a new empty content placeholder.
But I know of no way to paste a picture into the placeholder (other than manually)
Is it important that your picture be in a content placeholder?
Instead, can you just paste it onto the slide and size it to the full page?
That wouldn't be especially difficult
Assuming your have your picture on the clipboard something like this would do it.
You'd need to get a reference to the PPT app and replace
ActivePresentation.Slides(3) with a reference to the slide you want to work with:
Dim oSh As Shape
Set oSh = ActivePresentation.Slides(3).Shapes.Paste(1)
With oSh
' if you want to fill the slide with the picture
' even if that distorts the picture, set
' LockAspectRatio = msoFalse; otherwise, msoTrue
.LockAspectRatio = msoFalse
.Left = 0
.Top = 0
.Height = ActivePresentation.PageSetup.SlideHeight
.Width = ActivePresentation.PageSetup.SlideWidth
End With
-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ:
www.pptfaq.com
PPTools:
www.pptools.com
================================================
Thanks Steve.
I copy the pictures onto new blank slides.
There is no need for the picture to be in a content placeholder.
There is a need to display the pictures in full size of slide (minus
some margin).
I went into the direction of chart content placeholder because when I
did manual trials, it produced the best results, unlike normal pasting
onto blank slide which produced inconsistent and unexpected results.
I always start with copy Excel range as picture (Shift+Edit), and
accept the defaults
(Appearance: As shown on screen, Format: Picture).
Paste
I tried four machines with same build of XP and Office 2003 sp2. On
two machines the output was OK, while on the other two, the picture
was cutoff. It happened even when I sized the xl range to the size of
the slide.This is very strange and I could not expect a solution for
it from a remote newsgroup member.
Pasting into chart content placeholder always produced good results,
and scaling was done automatically. This is the oly reason why I
explored that direction. However, you ruled out this option, because
there is no way to programmatically paste a picture into the
placeholder.
PasteSpecial (ppPasteEnhancedMetafile)
Using PasteSpecial solved the issue of truncated picture.
I used your tips to modify my code. I list below the relevant portions
of it, for the benefit of other users.
It now maximizes the picture without distortion, and centers it
horizontally.
I still have 2 puzzles:
1. You had:
Dim oSh As Shape
Set oSh = ActivePresentation.Slides(3).Shapes.Paste(1)
And it works
In my implementation, I had a Type Mismatch error, and I had to leave
oShape undefined. Why?
2. The placement of the "Copy" statement turned out to be critical.
It works ok where it is placed, but when it is moved to the line:
'**Bad Location, the picture was truncated.
It appears that picture size was different, depending on where it was
copied. Why?
Sub PP_Creator()
Dim oPPApp As PowerPoint.Application
Dim oPres As PowerPoint.Presentation
Dim oSlide As PowerPoint.Slide
Dim oShape 'As ???
Dim strPP_FileName As String
Dim intSlideWidth As Integer
Dim intSlideHeight As Integer
intSlideWidth = 756 '** = 10.5 Inches
intSlideHeight = 576 '** = 8.0 Inches
strPP_FileName = "C:\MyFolder\MyFileName.ppt"
'** Bad Location
' Worksheets(1).Range("ppExport").CopyPicture Appearance:=xlScreen,
Format:=xlPicture
Set oPPApp = New PowerPoint.Application
Set oPres = oPPApp.Presentations.Add(True)
Set oSlide = oPres.Slides.Add(1, ppLayoutBlank)
With oPres.PageSetup
.SlideSize = ppSlideSizeCustom
.SlideWidth = intSlideWidth
.SlideHeight = intSlideHeight
.SlideOrientation = msoOrientationHorizontal
End With
'** Good Location
Worksheets(1).Range("ppExport").CopyPicture Appearance:=xlScreen,
Format:=xlPicture
oSlide.Shapes.PasteSpecial (ppPasteEnhancedMetafile)
Set oShape = oSlide.Shapes(1)
With oShape
.LockAspectRatio = True
'** Resize picture: Test if Width or Height is real constraint.
If .Width / intSlideWidth > .Height / intSlideHeight Then
'** It is a Width constraint
.Width = oPres.PageSetup.SlideWidth - 20
Else
'** It is a Height constraint
.Height = oPres.PageSetup.SlideHeight - 30
End If
.Top = 20
.Left = (intSlideWidth - .Width) / 2
End With
oPres.SaveAs strPP_FileName
Set oSlide = Nothing
Set oPres = Nothing
Set oShape = Nothing
End Sub
Thanks
dR