El Effe
07-16-2012, 02:45 PM
Hi all,
I turning crazy on a macro that used to work absolutely fine on PPT 2007. I haven't changed the code whatsoever, and since I upgraded to PPT2010, it does not work anymore.
It inserts pictures from a folder onto 1 slide. It still does, but the picture ration is not preserved. On debugging, it appears that it's the shape.scaleheight and shape.scalewidth methods which do not work (whether it be in this macro or another, it's still the case!).
This is *%§$# frustrating!!!
Has anyone had this issue? I searched on the web but could not find any indication as to what the problem may be...
I hope someone can help me. I have tons of pics to insert...
Here is the code:
Sub AllPicsOnOneSlide()
Dim strTemp As String
Dim strPath As String
Dim strFileSpec As String
Dim oSld As Slide
Dim oPic As Shape
Dim iCounter As Integer
strPath = "C:\Mypath\"
strFileSpec = "*.jpg"
strTemp = Dir(strPath & strFileSpec)
Set oSld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
iCounter = 0
Do While strTemp <> ""
If iCounter > 0 Then
ActivePresentation.Slides(oSld.SlideNumber).TimeLine.MainSequence.AddEffect (oPic, msoAnimEffectAppear, , msoAnimTriggerOnPageClick).Exit = msoTrue
Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0, _
Top:=0, _
Width:=100, _
Height:=100)
ActivePresentation.Slides(oSld.SlideNumber).TimeLine.MainSequence.AddEffect (oPic, msoAnimEffectAppear, , msoAnimTriggerWithPrevious).Exit = msoFalse
Else
Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0, _
Top:=0, _
Width:=100, _
Height:=100)
End If
With oPic
.ScaleHeight 1, msoTrue
.ScaleWidth 1, msoTrue
.LockAspectRatio = msoTrue
.Width = ActivePresentation.PageSetup.SlideWidth
If .Height > ActivePresentation.PageSetup.SlideHeight Then
.Height = ActivePresentation.PageSetup.SlideHeight
End If
.Top = (ActivePresentation.PageSetup.SlideHeight - .Height) / 2
.Left = (ActivePresentation.PageSetup.SlideWidth - .Width) / 2
End With
iCounter = iCounter + 1
strTemp = Dir
Loop
End Sub
Thanks very much in advance
El Effe
I turning crazy on a macro that used to work absolutely fine on PPT 2007. I haven't changed the code whatsoever, and since I upgraded to PPT2010, it does not work anymore.
It inserts pictures from a folder onto 1 slide. It still does, but the picture ration is not preserved. On debugging, it appears that it's the shape.scaleheight and shape.scalewidth methods which do not work (whether it be in this macro or another, it's still the case!).
This is *%§$# frustrating!!!
Has anyone had this issue? I searched on the web but could not find any indication as to what the problem may be...
I hope someone can help me. I have tons of pics to insert...
Here is the code:
Sub AllPicsOnOneSlide()
Dim strTemp As String
Dim strPath As String
Dim strFileSpec As String
Dim oSld As Slide
Dim oPic As Shape
Dim iCounter As Integer
strPath = "C:\Mypath\"
strFileSpec = "*.jpg"
strTemp = Dir(strPath & strFileSpec)
Set oSld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
iCounter = 0
Do While strTemp <> ""
If iCounter > 0 Then
ActivePresentation.Slides(oSld.SlideNumber).TimeLine.MainSequence.AddEffect (oPic, msoAnimEffectAppear, , msoAnimTriggerOnPageClick).Exit = msoTrue
Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0, _
Top:=0, _
Width:=100, _
Height:=100)
ActivePresentation.Slides(oSld.SlideNumber).TimeLine.MainSequence.AddEffect (oPic, msoAnimEffectAppear, , msoAnimTriggerWithPrevious).Exit = msoFalse
Else
Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0, _
Top:=0, _
Width:=100, _
Height:=100)
End If
With oPic
.ScaleHeight 1, msoTrue
.ScaleWidth 1, msoTrue
.LockAspectRatio = msoTrue
.Width = ActivePresentation.PageSetup.SlideWidth
If .Height > ActivePresentation.PageSetup.SlideHeight Then
.Height = ActivePresentation.PageSetup.SlideHeight
End If
.Top = (ActivePresentation.PageSetup.SlideHeight - .Height) / 2
.Left = (ActivePresentation.PageSetup.SlideWidth - .Width) / 2
End With
iCounter = iCounter + 1
strTemp = Dir
Loop
End Sub
Thanks very much in advance
El Effe