Excel:从单元格范围创建图像 [英] Excel: create image from cell range

查看:178
本文介绍了Excel:从单元格范围创建图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Excel VBA,我想创建一个显示单元格内容的图像。

Using Excel VBA, I want to create an image showing the content of a cell.


  • 我可以通过选择一个单元格,点击复制,选择另一个单元格,然后点击粘贴为图像来手动执行此操作。然后我可以选择图像并将其公式设置为 = $ B $ 2 ,例如。

  • 宏记录器告诉我相当于以下代码:

  • Manually, I can do this by selecting a cell, clicking on 'copy', selecting another cell, and clicking on 'paste as image'. Then I can select the image and set its formula to =$B$2, for example.
  • The Macro recorder tells me that this is equivalent to the following code:

Selection.Copy  
ActiveSheet.Pictures.Paste.Select
ActiveCell.FormulaR1C1 = "=R[1]C[1]"


  • I想要在不使用copy-paste-select命令的情况下实现相同目的。换句话说,我想用预定义的 FormulaR1C1 属性创建一个 Picture 对象。

  • I want to achieve the same without using the copy-paste-select commands. In other words, I would like to create a Picture object with predefined FormulaR1C1 property.

    我试过 ActiveSheet.Pictures.Add(左,上,宽,高)但只得到了运行时错误'1004':无链接粘贴。我不明白这意味着什么。

    I tried ActiveSheet.Pictures.Add(Left, Top, Width, Height) but only got Runtime error '1004': No link to paste. I don't understand what this means.

    我试过 ActiveSheet.Pictures.Insert ActiveSheet.Shapes.AddPicture ,但它们都需要一个文件名来加载外部图像文件,这不是我想要的。

    I tried ActiveSheet.Pictures.Insert and ActiveSheet.Shapes.AddPicture, but they both require a file name to load an external image file, which is not what I want.

    推荐答案

    您是否正在尝试获取链接的实时图片回到源范围,比如在Excel中使用相机工具?

    Are you trying to get a "live" picture which is linked back to the source range, like using the Camera tool in Excel?

    Sub Macro1()
    
        Dim s, rng As Range, rngDest As Range
    
        Set rng = ActiveSheet.Range("B2:C3")
        Set rngDest = ActiveSheet.Range("E10")
    
        rng.Copy
        With ActiveSheet.Pictures.Paste(link:=True)
            .Left = rngDest.Left
            .Top = rngDest.Top
        End With
    
    End Sub
    

    我不认为你可以使用复制/但要粘贴。

    I don't think you can get around using copy/paste though.

    这篇关于Excel:从单元格范围创建图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆