Log in

View Full Version : Solved: need help with: set object = ...pastespecial



werafa
05-21-2013, 03:29 PM
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'.

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
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

John Wilson
05-22-2013, 02:50 AM
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.


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

werafa
05-23-2013, 01:58 AM
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.
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

Tim

John Wilson
05-23-2013, 03:47 AM
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.

werafa
05-23-2013, 03:13 PM
I do have much to learn.
Thanks
Tim