Hi,
How do I apply 'Send to back' to a shape via macro code?
Thanks in advance.
Printable View
Hi,
How do I apply 'Send to back' to a shape via macro code?
Thanks in advance.
vb Code:
'~~> Replace "Rectangle 2" with the name of the relevant shape ActiveWindow.Selection.SlideRange.Shapes("Rectangle 2").Select ActiveWindow.Selection.ShapeRange.ZOrder msoSendToBack
Hi Koolsid! Thanks for the code.
I tried to combine it with
ActiveWindow.Selection.SlideRange.Shapes.AddPicture FileName:=filnavn, LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, Left:=640, Top:=158
like this
ActiveWindow.Selection.SlideRange.Shapes.AddPicture FileName:=filnavn, LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, Left:=640, Top:=158, ZOrder:=msoSendToBack
But it doesn't work.
How can I combine the two pieces of code?
Is that the only shape in that window?
No, there are several other shapes.
Well, you need to know the name of the shape so that you can select it via code and send it to the back...
How do I then set the name of my shape when I execute this piece of code?
ActiveWindow.Selection.SlideRange.Shapes.AddPicture FileName:=filnavn, LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, Left:=640, Top:=158
Thanks for your help.
Try this... See if this helps... Remember this will only work if there is no other shape at the same co-ordinates. If there are then you might need to select different parameters...
vb Code:
Sub Shps() Dim Shp As Shape, ShpName As String '~~> Sample. Change this as per your requirement filnavn = "C:\Documents and Settings\abhishek.shah\Desktop\koolsidz.gif" ActiveWindow.Selection.SlideRange.Shapes.AddPicture _ FileName:=filnavn, LinkToFile:=msoTrue, _ SaveWithDocument:=msoTrue, Left:=640, Top:=158 '~~> This will give you the names of all the shapes in that slide For Each Shp In ActivePresentation.Slides(1).Shapes '~~> An alternative that I can think of is to check '~~> the left and top of the shape and then get's it name '~~> and then send it to the back for example If Shp.Left = 640 And Shp.Top = 158 Then ShpName = Shp.Name Exit For End If Next '~~> Select Shape ActiveWindow.Selection.SlideRange.Shapes(ShpName).Select '~~> Send it to the back ActiveWindow.Selection.ShapeRange.ZOrder msoSendToBack End Sub
Hope this helps...
I ended up using your code this way:
Thank you very much for your help!Code:'find shape name
For Each Shp In ActivePresentation.Slides(ActiveWindow.View.Slide.SlideIndex).Shapes
If Shp.Left = 640 And Shp.Top = 158 Then
ShpName = Shp.Name
Exit For
End If
Next
'send arrow to back
ActiveWindow.Selection.SlideRange.Shapes(ShpName).Select
ActiveWindow.Selection.ShapeRange.ZOrder msoSendToBack
If you're trying to move a shape that you have added via code to the back, then you don't need to loop. Just capture the shape into a variable when you add it:
vb Code:
Dim oShape As Shape Set oShape = ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:=filnavn, LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, Left:=640, Top:=158) oShape.ZOrder msoSendToBack