插入sendToBack图像后

时间:2015-10-07 10:58:04

标签: excel vba excel-vba

我有一个有关插入照片的代码,但我无法将其发送回去。

我已尝试从this post复制行.ZOrder,但我的操作对象不是形状..

这是我的代码:

Private Sub CommandButton13_Click()
Dim p As Object
Dim rng0 As Range
Dim sh As Worksheet: Set sh = ActiveSheet
Set rng0 = Range("Q3:S5")
Application.ScreenUpdating = False
If UserForm1.txtImage = "" Then


rng0.Borders(xlEdgeBottom).LineStyle = xlContinuous


Exit Sub
Else
sh.Range("Q3:S5").Merge
Set p = sh.Pictures.Insert(UserForm1.txtImageBackground)
sh.Shapes(p.name).LockAspectRatio = False

If rng0.Cells.Count = 1 Then Set rng0 = rng0.MergeArea
With rng0
    p.Top = .Top
    p.Left = .Left
    p.Width = .Width
    p.Height = .Height
End With
Application.ScreenUpdating = True
End If


Selection.ShapeRange.ZOrder msoSendToBack
Application.ScreenUpdating = True




'        shp.ScaleHeight Factor:=1, RelativeToOriginalSize:=msoTrue
'        shp.ScaleWidth Factor:=1, RelativeToOriginalSize:=msoTrue
'        shp.ZOrder msoSendToBack
End Sub

谢谢!

1 个答案:

答案 0 :(得分:1)

pPicture,因此您可以直接使用ZOrder

p.ZOrder msoSendToBack
编辑:我的错误。 Zorder是图片的属性,是只读的。你需要:

p.ShapeRange.ZOrder msoSendToBack