Consulting

Results 1 to 9 of 9

Thread: How to paste & then resize an image

  1. #1
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location

    How to paste & then resize an image

    hi, I Have borrowed one of John's magic modules to resize a shape, and tried to marry it with a paste command - end result is paste as enhanced metafile, then set position and size <not>

    I need to activate the shape to make it work under the current approach. How can I reliably identify it? or is there a better way?

    Sub PasteTable()
    Dim myShape As Object
        'paste excel table as enhanced metafile, then resize to full width
        ActiveWindow.Selection.SlideRange(1).Shapes.PasteSpecial ppPasteEnhancedMetafile
        Set myShape = ActiveWindow.Selection 'for debugging
        With ActiveWindow.Selection.ShapeRange(1)
       .LockAspectRatio = True
       .Top = 70 'points from top
       .Left = 10 'points from left
       .Width = 700 'points wide
        End With
    End Sub

    Thanks all.
    Last edited by Aussiebear; 04-09-2023 at 09:30 PM. Reason: Adjusted the code tags
    Remember: it is the second mouse that gets the cheese.....

  2. #2
    VBAX Contributor
    Joined
    May 2008
    Posts
    198
    Location
    The returned value of PasteSpecial is the shaperange which is pasted, so you can use that directly:
    Sub PasteTable()
    Dim myShape As Object
         'paste excel table as enhanced metafile, then resize to full width
    Set myShape = ActiveWindow.Selection.SlideRange(1).Shapes.PasteSpecial(ppPasteEnhancedMetafile)
        With myShape
       .LockAspectRatio = True
       .Top = 70 'points from top
       .Left = 10 'points from left
       .Width = 700 'points wide
        End With
    End Sub
    Last edited by Aussiebear; 04-09-2023 at 09:31 PM. Reason: Adjusted the code tags

  3. #3
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location

    Thanks

    So simple when you know how.
    Thanks

    and to anyone else reading this: there are links elsewhere in this forum to instructions for making custom ribbon buttons to run subs like this

    Thanks to everyone who has helped me thus far
    Tim
    Remember: it is the second mouse that gets the cheese.....

  4. #4
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location

    hmmm. not as good as I hoped....

    Quote Originally Posted by Cosmo
    Set myShape = ActiveWindow.Selection.SlideRange(1).Shapes.PasteSpecial(ppPasteEnhancedMetafile)
    is giving me a " Shapes (unknown member) : invalid request. The specified data type is unavailable." error

    I am using ppt 2007, and am not sure what I have missed. ideas?

    Thanks
    Last edited by Aussiebear; 04-09-2023 at 09:32 PM. Reason: Adjusted the code tags
    Remember: it is the second mouse that gets the cheese.....

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    There's a space that shouldn't be there in "ppPasteEnhancedMet afile". If that's really there that will be the problem. If not are you sure whatever you have in the clipboard can be pasted as an EMF. Try manually paste special and see if it's an option.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location
    John, The space is only in the VBAX post. Retyping in lowercase is picked up and capitalised correctly.

    what is worse is that the @#$ thing has just decided to work and I can't make it play up in order to debug it. I think I will take a couple of aspirin and have a little nanna nap -- the previous comment about how wonderful you guys are stands.....
    Remember: it is the second mouse that gets the cheese.....

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Good it's working.

    You might want to know that ppPasteEnhancedMetafile will only be recognised as a constant while PowerPoint is the active application. Hard to see how it wouldn't be but it enumerates to 2 so you can use that.

    Sub PasteTable()
    Dim myShape As Object
         'paste excel table as enhanced metafile, then resize to full width
    Set myShape = ActiveWindow.Selection.SlideRange(1).Shapes.PasteSpecial(DataType:=2)
        With myShape
       .LockAspectRatio = True
       .Top = 70 'points from top
       .Left = 10 'points from left
       .Width = 700 'points wide
        End With
    End Sub
    Last edited by Aussiebear; 04-09-2023 at 09:33 PM. Reason: Adjusted the code tags
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  8. #8
    I wonder do I need any other image processors for help?
    Best Regards,
    Arron

    I am testing about image resizers to resize images, any ideas?


    Next Tomorrow is Another Day.

  9. #9
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location
    what do you mean by this, and what do you wish to achieve?

    this pastes an exzcel range as an image - and works with the normally available paste-special options for this task.
    are you looking for something non-standard?
    Remember: it is the second mouse that gets the cheese.....

Posting Permissions

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