2

I'm trying to simply make a graph in VBA but get the error:

user defined type not defined

I've been able to dim it as an object and produce it, but then I can't edit any of its member properties. I'm running VBA from MS-Access but I'm unsure that would affect it.

Here's my full code

    Dim TATchart As ChartObject
    Set TATchart = wrkSht.ChartObjects.Add(Left:=200, Width:=375, Top:=50, Height:=225)
    With TATchart.Chart
        Set ChartType = xlXYScatterLines
        .SetSourceData Source:=wrkSht.Range(wrkSht.cells(1, 1), CurCell.offset(0, 1))
        Set .Title = "Total Over Time (MAW)"
    End With

EDIT: wrkSht is initialized as a worksheet and has been working fine.

HansUp
  • 95,961
  • 11
  • 77
  • 135
Chris Chevalier
  • 620
  • 1
  • 7
  • 20

1 Answers1

3

If you want to Dim something As ChartObject, you will need to add a reference to your project. From the VB Editor's main menu, choose Tools->References. Then scroll down the list until you find "Microsoft Excel < version > Object Library" and check the box next to it.

Then your Dim should compile.

Dim TATchart As ChartObject

You might prefix it with Excel as a reminder where it comes from:

Dim TATchart As Excel.ChartObject

Note you would have encountered a similar compile error at the xlXYScatterLines constant because that is also unknown to Access VBA without the Excel type library reference.

HansUp
  • 95,961
  • 11
  • 77
  • 135