OK, 2003. Good.
> OK, 2003. Good.
>
[quoted text clipped - 52 lines]
> 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
Steve Rindsberg - 07 Mar 2008 16:51 GMT
> I still have 2 puzzles:
> 1. You had:
[quoted text clipped - 3 lines]
> In my implementation, I had a Type Mismatch error, and I had to leave
> oShape undefined. Why?
Because it's a part of the PowerPoint object model and you're writing code to run in
Excel. You could either
Dim oShape as Object
or
Set a reference to PowerPoint then
Dim oShape as Shape
or
Dim oShape as PowerPoint.Shape
Then you can make another change that may make your code a bit more reliable ... see
comments below.
> 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?
I don't have a reliable answer for that, but I've noticed that if I copy from Excel
then start PPT, I get different results on the clipboard (and from pasting) than if I
do the copy in Excel after starting PPT. That would seem to explain your results too.
> Sub PP_Creator()
> Dim oPPApp As PowerPoint.Application
[quoted text clipped - 30 lines]
> oSlide.Shapes.PasteSpecial (ppPasteEnhancedMetafile)
> Set oShape = oSlide.Shapes(1)
Try
Set oShape = oSlide.Shapes.PasteSpecial (ppPasteEnhancedMetafile)(1)
Then it won't rely on pasting into a blank slide.
> With oShape
> .LockAspectRatio = True
[quoted text clipped - 21 lines]
> Thanks
> dR
-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================