vba 如何将图像从另一个工作表复制到活动工作表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17023212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 21:34:13  来源:igfitidea点击:

How to copy image from another sheet to active sheet

excel-vbaexcel-2010vbaexcel

提问by Sylca

I've inserted some images into Sheet2and 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:

我已经插入了一些图像Sheet2,我想将它们复制到我的Sheet1(即 ActieSheet)中。当我在第 5 行之后在 column1 中键入图像名称时,将执行该图像副本Sheet1。我尝试了一些东西,但它们不起作用,但是,我已经组装了几行代码或我希望它实现的方式。这里是:

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

任何帮助将不胜感激。谢谢

回答by

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