PDA

View Full Version : Can't set variable to ShapeRange while Pasting in PPT 2013



Chris Macro
07-09-2014, 08:37 AM
I came across this problem while writing a blog post (see post here (http://www.thespreadsheetguru.com/blog/2014/6/30/copy-paste-multiple-excel-ranges-to-separate-powerpoint-slides-with-vba)) that shows how to copy/paste data from Excel to PowerPoint slides. I realized that I was getting errors when I tried to set a variable equal to a newly pasted object in PPT 2013 but in PPT 2007 it worked fine (I don't have 2010 to test with). Below is how I ended up writing my code to handle both versions of PowerPoint but was wondering if this is an error on Microsoft's side or if they changed something for an improvement. Curious if any one else has had this problem or if there is a better way to accommodate 2007-2013 versions of PowerPoint? If you need context, my entire code is posted in the blog post link in the first sentence. Thanks!


'Paste to PowerPoint and position
On Error Resume Next
Set shp = myPresentation.Slides(MySlideArray(x)).Shapes.PasteSpecial(DataType:=2) 'Excel 07-10
Set shp = PowerPointApp.ActiveWindow.Selection.ShapeRange 'Excel 2013
On Error GoTo 0

John Wilson
07-10-2014, 04:15 AM
Sounds like a bug to me.

Not all versions select the shape after pasting which is part osf the problem but in 2013 the reference oshp is lost after it is paste specialled.

You could try as a workaround declaring oshp as a Shape

and

Set shp = myPresentation.Slides(MySlideArray(x)).Shapes.PasteSpecial(DataType:=2)(1)

I think this will work in all versions.

Or the shape pasted will always be the front shape so you could reference it as Shapes(osld.Shapes.Count)

Chris Macro
07-11-2014, 06:47 AM
Thanks for the work around suggestions John. Is there any way you could let the Microsoft PPT team know about this bug? It caused me a big headache and I'm sure it is causing others trouble as well. Retaining a shape reference after pasting is very valuable when dealing with automating PowerPoint creation. Thanks again!

John Wilson
07-11-2014, 06:51 AM
Absolutely. It may break several of our AddIns too. Can you test your end whether the ref is lost with a simple paste in code (instead of PasteSpecial)

Chris Macro
07-13-2014, 05:23 PM
Yes, I get the same error while just using Paste. Hopefully Microsoft will fix this!

John Wilson
07-13-2014, 11:57 PM
I don't get the error with Paste or even with PasteSpecial if I chose Default.
I have reported it as a bug but I have no control over when or if MSFT fix it!

Chris Macro
07-14-2014, 05:43 AM
oh, so you think its a bug with just pasting as enhanced metafiles? I'm using your alternative method of referencing the shape index # and it's working beautifully. Thanks for you help and submitting the bug report!