Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Class programming - how to return chartobject from a class?
Hi,
I have the following setup: 1. Class module "ChartHandler" 2. Module "Tester" In ChartHandler, I have a function to return an instance of a ChartObject. The chart is present in a worksheet in my workbook. I successfully claim the chart with the following code: Public Function claimChartObject(ByVal s As String) as ChartObject Debug.Print ws.Name ' prints worksheet name correctly Debug.Print ws.ChartObjects(s).Name ' prints the name correctly claimChartObject = ws.ChartObjects(s) End Function The above function works as it should. However, when I try to get the chartobject from my module, it fails. The code in my module is something like this: Dim coChart As ChartObject Dim handler As ChartHandler ' Creates an instance of ChartHandler - works ' Some initialization... ' .... Set coChart = handler.claimChartObject("myChart") ' <-- this fails! If I try to snatch the chartobject with the following line, it works: Set coChart = Worksheets("chart").ChartObjects("myChart") So my question is, how to I return the chartobject from the class?? I tried changing "Public Function" to "Property Get" but without success. Any help much appreciated! Fredrik |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Class programming - how to return chartobject from a class?
|
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Class programming - how to return chartobject from a class?
Fredrik,
Because you are returning an object, you need the Set keyword. Public Function claimChartObject(ByVal s As String) as ChartObject Set claimChartObject = ws.ChartObjects(s) End function NickHK wrote in message ups.com... Hi, I have the following setup: 1. Class module "ChartHandler" 2. Module "Tester" In ChartHandler, I have a function to return an instance of a ChartObject. The chart is present in a worksheet in my workbook. I successfully claim the chart with the following code: Public Function claimChartObject(ByVal s As String) as ChartObject Debug.Print ws.Name ' prints worksheet name correctly Debug.Print ws.ChartObjects(s).Name ' prints the name correctly claimChartObject = ws.ChartObjects(s) End Function The above function works as it should. However, when I try to get the chartobject from my module, it fails. The code in my module is something like this: Dim coChart As ChartObject Dim handler As ChartHandler ' Creates an instance of ChartHandler - works ' Some initialization... ' .... Set coChart = handler.claimChartObject("myChart") ' <-- this fails! If I try to snatch the chartobject with the following line, it works: Set coChart = Worksheets("chart").ChartObjects("myChart") So my question is, how to I return the chartobject from the class?? I tried changing "Public Function" to "Property Get" but without success. Any help much appreciated! Fredrik |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Class programming - how to return chartobject from a class?
Eend: Thanks, aldready done that but I excluded that part in my code-snippet NickHK: Terrific, that did the trick. Many thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Class modules: parametrize class object fields | Excel Programming | |||
VBA Class Modules | Excel Programming | |||
class module programming? | Excel Programming | |||
Class within a class | Excel Programming | |||
RaiseEvent from a class contained in a 2nd class collection? | Excel Programming |