PDA

View Full Version : Select shapes by name based on named range



areisett
09-13-2013, 01:46 PM
Hi,

I'm trying to use the following code to copy and paste a shape from one ppt to another. I'm then adding a transparent shape over the original shape that will receive action settings (I'm doing this because the original shape is a flowchart object and doesn't retain its link functionality once converted to a pdf).

The part of the code that is giving me trouble is selecting the shapes I want to copy. I have assigned a named range in an excel spreadsheet which contains the name of the shape. I then gave the shape the same name in my ppt that I'm copying the shape from. The error I receive is on this step:

With pres_temp
.Slides(1).Shapes(Selection).Copy
End With

And the error is "Shapes(unknown member): failed".

However, when I hover over "selection" it returns the correct name of the shape that I want.

I'd eventually like to use the offset function to have the VBA loop through a list of shapes in the excel spreadsheet and copy and paste them by name. Is there any way to make this work? Please help! Thank you!


start_start_name = Range("start_start_name").Value


Range("start_start_name").Select


Do Until IsEmpty(ActiveCell)


i = 1

With pres_temp
.Slides(1).Shapes(Selection).Copy
End With

With pres
.Slides(1).Shapes.Paste
End With

Top = pres.Slides(1).Shapes(Selection).Top
Left = pres.Slides(1).Shapes(Selection).Left
Width = pres.Slides(1).Shapes(Selection).Width
Height = pres.Slides(1).Shapes(Selection).Height

With pres.Slides(1)
With .Shapes.AddShape(Type:=msoShapeRectangle, Left:=Left, Top:=Top, Width:=Width, Height:=Height)
.Name = "overlay_" & i
End With
End With

With pres.Slides(1).Shapes("overlay_" & i).ActionSettings(ppMouseClick)
.Action = ppActionHyperlink
.Hyperlink.SubAddress = 2
End With

pres.Slides(1).Shapes("overlay_" & i).Fill.Transparency = 1
pres.Slides(1).Shapes("overlay_" & i).Line.Transparency = 1

ActiveCell.Offset(1, 0).Select

i = i + 1
Loop

John Wilson
09-14-2013, 06:28 AM
Are you running the code in Excel or PowerPoint?
Have you set the correct reference?

The Hyperlink.Subaddress can never be =2 BTW. It needs to be a string "SlideID,SlideIndex,SlideTitle" eg "257,3,MyTitle"