Consulting

Results 1 to 7 of 7

Thread: [Insane] Scaleheight & scalewidth

  1. #1
    VBAX Newbie
    Joined
    Jul 2012
    Posts
    3
    Location

    Angry [Insane] Scaleheight & scalewidth

    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:
    [VBA]
    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
    [/VBA]

    Thanks very much in advance

    El Effe

  2. #2
    VBAX Newbie
    Joined
    Jul 2012
    Posts
    3
    Location
    An update:

    In fact, when I insert a picture manually, through the ribbon (Insert/picture), the ratio of the inserted picture is not preserved either! The picture is inserted with the format of the slide and I can't reset its ratio by any means!!!
    I think this is where the problem lies, but I am no wiser as to how I can manage it or why it happens...
    I can't find any info on the web. I cannot be the only one having this issue...

    Any idea, anyone?

    Thx in advance

    El Effe

  3. #3
    VBAX Regular
    Joined
    Jul 2011
    Posts
    40
    Location
    DELETED see below
    Last edited by dougbert; 08-21-2012 at 11:31 PM.

  4. #4
    VBAX Regular
    Joined
    Jul 2011
    Posts
    40
    Location
    Hi El,

    I know just how *%§$# frustrating this can be. Please read some the posts in a thread to which I, among others, posted some ideas on this topic. Maybe you'll find another way to approach this problem.

    One suggestion might be to leave your .LocAspectRatio as msoTrue. Then, just use .Height (instead of .ScaleHeight, etc.), along with .Top and .Right to place the upper right-hand corner of the photo whereever you'd like the photo to appear on each slide. The locked aspect ratio will take care of the picture size, adjust .Height as necessary to get just the right size for you photos. Use either .Height OR .Width; your preference. Don't use both at the same time.

    Or, just try "commenting out" both the lines with .ScaleHeight and .ScaleWidth out and run the macro to see if that works better for you.
    Last edited by dougbert; 08-21-2012 at 11:29 PM.

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Arguably it should never have worked in 2007.

    If you set the width and height to be 100 what should the scalewidth and height be??

    Anyway maybe this would work for you.

    [VBA]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:=msoTrue, _
    Height:=msoTrue)
    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:=msoTrue, _
    Height:=msoTrue)
    End If

    With oPic
    .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[/VBA]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    VBAX Newbie
    Joined
    Jul 2012
    Posts
    3
    Location
    Thank you so much John and Dougbert for taking the time to reply!!

    Your solution is working, John! That's perfect.
    I still have not figured out why my code used to work in PPT 2007 and not in PPT 2010...

    Anyway, thanks again.
    Sorry for the delay in coming back to the forum to check your replies!

    El Effe

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    When you use Addpicture the width and height are OPTIONAL. If you do not specify it will default to the actual width / height. You should not set it to an arbitary value such as 100. In some versions scaleheight will correct this but in others it will take 100 to be the original scaleheight and scalewidth. (understandably as you have told PowerPoint that!) Setting the value to msoTrue or -1 ensures that the original scaleheight/width are used.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •