vba 在 Excel 用户窗体中显示“实时”图表数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31598704/
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
Displaying "live" chart data in Excel Userform
提问by user3794203
I have been researching the modes of displaying charts in a userform.
我一直在研究在用户表单中显示图表的模式。
The general consensus seems to be to save the chart as a .GIF file and then upload this within the userform as an image. However, this would mean that anyone using the userform would have to have the file saved as an image to view the information. (I do not believe that any of my associates will take the time to learn how to do this, they just want a quick chart-view).
普遍的共识似乎是将图表保存为 .GIF 文件,然后将其作为图像上传到用户表单中。但是,这意味着任何使用用户表单的人都必须将文件另存为图像才能查看信息。(我不相信我的任何同事会花时间学习如何做到这一点,他们只是想要一个快速的图表视图)。
Is there a workaround to display the chart (which is constantly being updated by data that comes in) within a userform?
是否有一种解决方法可以在用户表单中显示图表(不断被传入的数据更新)?
I tried multiple avenues and did not finding anything. Also, my Excel 2013 does not appear to have the Microsoft Office Charts option within the Toolbox, is this something that has been changed?
我尝试了多种途径,但没有找到任何东西。另外,我的 Excel 2013 的工具箱中似乎没有 Microsoft Office 图表选项,这是否已更改?
回答by kelvin 004
Case 1: If the chart is on the worksheet, it will be easier as below:
情况 1:如果图表在工作表上,则如下所示会更容易:
Private Sub UserForm_Initialize()
Dim Fname As String
Call SaveChart
Fname = ThisWorkbook.Path & "\temp1.gif"
Me.Image1.Picture = LoadPicture(Fname)
End Sub
Private Sub SaveChart()
Dim MyChart As Chart
Dim Fname As String
Set MyChart = Sheets("Data").ChartObjects(1).Chart
Fname = ThisWorkbook.Path & "\temp1.gif"
MyChart.Export Filename:=Fname, FilterName:="GIF"
End Sub
Case 2: If chart is not on the worksheet, you may need to create a temporary chart, save it as GIF, delete it, and finally load the picture {
情况二:如果图表不在工作表中,您可能需要创建一个临时图表,将其保存为GIF,删除它,最后加载图片{
Me.Image1.Picture = LoadPicture(Fname)
} when the Userform is initialized.
初始化用户窗体时。
Case 1 is easier to code. The above code still works even I cut and paste the chart in a later-hidden worksheet.
情况 1 更容易编码。即使我将图表剪切并粘贴到后来隐藏的工作表中,上述代码仍然有效。

