SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 202 | Next

Jim DeMarco

"Pro Excel 2007 VBA"

This will hold the return value for our function.
4. Move the code shown in bold in the following code block from the PlaceChartDynamic
subroutine into GetChartInfo, under the variable declaration we just added.
The GetChartInfo code should look like this:
Private Function GetChartInfo(MyChart As ChartObject) As Variant
Dim varReturn As Variant
Dim arrChartInfo(3) As Variant
With MyChart
arrChartInfo(0) = .Name
arrChartInfo(1) = .Top
arrChartInfo(2) = .Left
arrChartInfo(3) = .Height
End With
End Function
5. Add the following code to assign the array to the return variable, and finally to assign
varReturn as the return value of the function:
varReturn = arrChartInfo
GetChartInfo = varReturn
The completed function should look like that in Listing 5-4.
CHAPTER 5 n CHARTING IN EXCEL 2007 216
Listing 5-4. The GetChartInfo Subroutine
Private Function GetChartInfo(MyChart As ChartObject) As Variant
Dim varReturn As Variant
Dim arrChartInfo(3) As Variant
With MyChart
arrChartInfo(0) = .Name
arrChartInfo(1) = .Top
arrChartInfo(2) = .Left
arrChartInfo(3) = .Height
End With
varReturn = arrChartInfo
GetChartInfo = varReturn
End Function
Completing the PlaceChartDynamic Procedure
The PlaceChartDynamic subroutine currently looks like Listing 5-5, and is ready for a few modifications,
including using the GetChartInfo method we just created.
Listing 5-5. The PlaceChartDynamic Routine Is Ready for Modifications
Sub PlaceChartDynamic()
Dim spacer As Integer
spacer = 25
Range("A6:C9").


Pages:
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214