简体   繁体   English

Excel自动将单元格范围转换为另一张纸上的图片并自动更新

[英]excel that automatically convert cell range to picture on another sheet and automatically update

I want to creat an excel workbook that can convert cell rang on a sheet to picture on another sheet and is capable of authomatically updating the picture should there be any modification on the source sheet. 我想创建一个Excel工作簿,该工作簿可以将工作表上的单元格范围转换为另一工作表上的图片,并且能够对源工作表上的任何内容进行自动更新。 I have no macros background. 我没有宏背景。

Here is an example that you can adapt. 这是您可以适应的示例。 We want to capture changes to range C3:F10 我们想要捕获范围C3:F10的更改

These are input changes rather than the result of calculation. 这些是输入更改,而不是计算结果。

If the cells in this block are changed, the block is copied as Picture and the Picture pasted in Sheet3 near cell C5 如果更改了该块中的单元格,则将该块复制为“图片”,并将“图片”粘贴到Sheet3中靠近单元格C5的位置

Insert the following Event macro in the worksheet code area: 在工作表代码区域中插入以下事件宏:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim r1 As Range, r2 As Range, sv As Range
    Dim sh As Worksheet
    Set r1 = Range("C3:F10")
    Set r2 = Sheets("Sheet3").Range("C5")

    If Intersect(Target, r1) Is Nothing Then Exit Sub

    Set sv = Selection
    Set sh = ActiveSheet

    Application.EnableEvents = False
        r1.CopyPicture Appearance:=xlScreen, Format:=xlPicture
        Sheets("Sheet3").Select
        On Error Resume Next
            ActiveSheet.Shapes("Latest Snap").Delete
        On Error GoTo 0
        r2.Select
        ActiveSheet.Paste
        Selection.Name = "Latest Snap"
        sh.Select
        sv.Select
    Application.EnableEvents = True
End Sub

Because it is worksheet code, it is very easy to install and automatic to use: 因为它是工作表代码,所以非常易于安装和自动使用:

  1. right-click the tab name near the bottom of the Excel window 右键单击Excel窗口底部附近的选项卡名称
  2. select View Code - this brings up a VBE window 选择查看代码-这将打开一个VBE窗口
  3. paste the stuff in and close the VBE window 将内容粘贴并关闭VBE窗口

If you have any concerns, first try it on a trial worksheet. 如果您有任何疑问,请先在试用版工作表上尝试一下。

If you save the workbook, the macro will be saved with it. 如果您保存工作簿,则宏将随其一起保存。 If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx 如果您在2003年以后使用Excel版本,则必须将文件另存为.xlsm而不是.xlsx

To remove the macro: 删除宏:

  1. bring up the VBE windows as above 如上调出VBE窗口
  2. clear the code out 清除代码
  3. close the VBE window 关闭VBE窗口

To learn more about macros in general, see: 要总体上了解有关宏的更多信息,请参见:

http://www.mvps.org/dmcritchie/excel/getstarted.htm http://www.mvps.org/dmcritchie/excel/getstarted.htm

and

http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx

To learn more about Event Macros (worksheet code), see: 要了解有关事件宏(工作表代码)的更多信息,请参见:

http://www.mvps.org/dmcritchie/excel/event.htm http://www.mvps.org/dmcritchie/excel/event.htm

Macros must be enabled for this to work! 必须启用宏才能使其正常工作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM