Consulting

Results 1 to 5 of 5

Thread: Solved: need help with: set object = ...pastespecial

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

    Solved: need help with: set object = ...pastespecial

    Hi all, I have some code that did work in office 2010. I have upgraded to 2013, and have also added some extra shapes to the relevant slide - and the code now fails after the 'with myshape'.

    [vba]Sub PasteTable()
    'paste excel table as enhanced metafile, then resize to full width
    Dim myShape As Object
    Set myShape = ActiveWindow.Selection.SlideRange(1).Shapes.PasteSpecial(ppPasteEnhancedMet afile)
    With myShape
    .LockAspectRatio = True
    .Top = 60 'points from top
    .Left = 10 'points from left
    .Width = 700 'points wide
    End With
    End Sub[/vba]
    myShape appears in the locals window as an object/shaperange, and running a myshape.name returns 'command cannot be applied to a shape range with multiple shapes'.

    can anyone spot what I am doing wrong?

    thanks
    Tim
    Remember: it is the second mouse that gets the cheese.....

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,095
    Location
    I don't have 2013 handy to check but:

    PasteSpecial returns a ShapeRange

    so I would declare is as such (not an Object)

    I'm guessing that 2010 (wrongly really) assumes that the Shape is the first member of the ShapeRange and 2013 is more precise.


    [vba]Sub PasteTable()
    'paste excel table as enhanced metafile, then resize to full width
    Dim myShapeRange As ShapeRange
    Dim myShape As Shape
    Set myShapeRange = ActiveWindow.Selection.SlideRange(1).Shapes.PasteSpecial(ppPasteEnhancedMet afile)
    Set myShape = myShapeRange(1)
    With myShape
    .LockAspectRatio = True
    .Top = 60 'points from top
    .Left = 10 'points from left
    .Width = 700 'points wide
    End With
    End Sub

    [/vba]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location
    Thanks once again John. If you were over this side of the ditch I'd buy you a beer.

    one slight mod, and some housekeeping, and here it is for anyone else to try.
    [VBA]Sub PasteTable()
    'paste excel table as enhanced metafile, then resize to full width
    Dim myShapeRange As ShapeRange
    Dim myShape As Shape

    Set myShapeRange = ActiveWindow.Selection.SlideRange(1).Shapes.PasteSpecial(ppPasteEnhancedMet afile)
    Set myShape = myShapeRange(myShapeRange.Count)
    With myShape
    .LockAspectRatio = True
    .Top = 60 'points from top
    .Left = 10 'points from left
    .Width = 700 'points wide
    End With
    Set myShapeRange = Nothing
    Set myShape = Nothing
    End Sub[/VBA]

    Tim
    Remember: it is the second mouse that gets the cheese.....

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,095
    Location
    When you paste myShapeRange is the range of pasted shapes only NOT all shapes on the slide so mySlideRange(1) is usually correct. As long as you paste just one shape mySlideRange(mySlideRange,Count) will be the same thing but is not really needed.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location
    I do have much to learn.
    Thanks
    Tim
    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
  •