How to copy image from another sheet to active she

2019-07-31 19:58发布

问题:

I've inserted some images into Sheet2 and I'd like to copy them into my Sheet1(that will be ActieSheet). That image copy will be executed when I type image names in column1 after 5th row on Sheet1. I've tried few things but they don't work, however, I've assembled few lines of code or the way that I'd like it to be implemented. Here it is:

Private Sub Worksheet_Change(ByVal Target As Range)

    Dim picName As String

    If Target.Column = 1 And Target.Row >= 5 Then
        picName = Target.Offset(0, 0).Value

        'Here goes the rest of the code

    End If

End Sub

Any help will be appreciated. Thanks

回答1:

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim picName As String
    If Target.Column = 2 And Target.Row >= 5 Then
        picName = Target.Value
        Copy_Images picName
    End If
End Sub


Private Sub Copy_Images(imageName As String)
    Dim sh As Shape
    For Each sh In Sheets(2).Shapes
        If sh.Name = imageName Then
            sh.Copy
            Sheets(1).Pictures.Paste
        End If
    Next
End Sub