Search code examples
excelvbaobjectuserform

Run time error '1004' Application defined or Object defined error


I'm learning to make a chart in the userform but have trouble with the error message

"Run time error 1004 Application-defined or Object-defined error"

At first it was successful, but then I created a new macro, copied and pasted and the error '1004' appeared.

My code as follows:

Private Sub UpdateChart()
    Dim PA_Chart As Object
    Dim NamaFL As String
    Application.ScreenUpdating = False
    Set PA_Chart = Sheets("DummyChart").ChartObjects(ChartKe).Chart
    PA_Chart.Parent.Width = 300
    PA_Chart.Parent.Height = 150
    On Error Resume Next
    'menyimpan Chart sebagai Gif
    NamaFL = ThisWorkbook.Path & "\" & "WPAGraph.gif"
    PA_Chart.Export Filename:=NamaFL, FilterName:="GIF"
    'Menampilkan Chart Pada Image1
    Me.Image1.Picture = LoadPicture(NamaFL)
    Application.ScreenUpdating = True
End Sub

Solution

  • Everything looks fine except .ChartObjects(ChartKe). ChartKe is not found anywhere in the code. You can try referencing by actual name, e.g. .ChartObjects("Chart 1")