How to set an arg list for my VBA functions
I see two problems with the code you posted. First, the elements of an Enum
must follow the same rules as for a variable name, so the space in your
first element of the thisLabelArg2 Enum cannot have a space in the middle of
it as you show. The second problem is in the 2nd argument for the thisLabel
function call shown here...
ChartTitle.Characters.Text = thisLabel(cumChartLabels, "Chart Title")
You are trying to pass "ChartTitle" as the 2nd argument; however,
"ChartTitle" is a String value, but your declaration for the 2nd argument is
a thisLabelArg2 Enum, which is not a String value. If you don't want to pick
the value from the drop down list (not sure why you wouldn't as you said in
your initial posting that is what you wanted to be able to do), you could
construct your function call this way...
ChartTitle.Characters.Text = thisLabel(cumChartLabels, _
thisLabelArg2.ChartTitle)
where I am assuming you are correcting your first mistake by simply removing
the internal space. You are also showing two End Function statements, but
I'm assuming that is from some bad Copy/Paste'ing. Also, while I don't think
it is contributing to any errors, I find your If-Then block construction
(especially without better indenting) to be very hard to read... I never use
one-line ElseIf statements like you showed. One final comment for when you
get this all working... inside your code, you do not have to use the 1, 2, 3
etc. equated values of your Enum elements, you can use EnumName.ElementName
instead. For example, instead of this...
If labelSeries = 1 Then
you could use this (more self-documenting) version instead
If labelSeries = thisLabelArg1.cumChartLabels Then
Rick
"shelfish" wrote in message
...
Many thanks. I'm getting a "User defined type not defined..." error.
Here's what I've got:
Public Enum thisLabelArg1
cumChartLabels = 1
monthlyCountChartLabels = 2
top5ChartLabels = 3
End Enum
Public Enum thisLabelArg2
Chart Title = 1
X_Axis_Label = 2
Primary_Axis_Label = 3
Secondary_Axis_Label = 4
End Enum
Function thisLabel(labelSeries As thisLabelArg1, labelType As
thisLabelArg2) As String ## Error on this line ##
If labelSeries = 1 Then Set thisChartLabel = cumChartLabels
ElseIf labelSeries = 2 Then Set thisChartLabel =
monthlyCountChartLabels
ElseIf labelSeries = 3 Then Set thisChartLabel =
top5ChartLabels
End If
If labelType = 1 Then findLabelType = "Chart Title"
ElseIf labelType = 2 Then findLabelType = "X Axis"
ElseIf labelType = 3 Then findLabelType = "Primary"
ElseIf labelType = 4 Then findLabelType = "Secondary"
End If
thisLabel = Range("'" & chartDataSheetName & "'!" &
thisChartLabel.Find(labelType).Offset(1, 0).Address).Value
End Function
thisLabel = Range("'" & chartDataSheetName & "'!" &
thisChartLabel.Find(labelType).Offset(1, 0).Address).Value
End Function
Sub...
...ChartTitle.Characters.Text = thisLabel(cumChartLabels, "Chart
Title")
End Sub
|