Displaying “live” chart data in Excel Userform

倾然丶 夕夏残阳落幕 提交于 2019-12-03 10:06:44

Case 1: If the chart is on the worksheet, it will be easier as below:

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 {

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!