Compiler Error: Expected Array
Posted by Edward C. on April 03, 2001 2:15 PM
Hi,
I get the error message:
Compiler Error: Expected Array
when I run a macro I built. I believe it is not happy with the way I declared my array, but I don't know whats wrong because I took this example straight from the O'Reilly book "Writing Excel Macros" by Steven Roman. If anyone sees something wrong or has a suggestion I would greatly appreciate any feedback you can give me.
Thanks
Edward
---------------------------------------
Option Explicit
Dim cChartSheets As Integer
Dim sChartSheetNames As String
---------------------------------------
Public Sub UserForm_Initialize()
Dim ws As Object ' Worksheet
ReDim sChartSheetNames(1 To 10)
lstChartSheets.Clear
cChartSheets = 0
For Each ws In ActiveWorkbook.Charts
cChartSheets = cChartSheets + 1
'Redimension arrays if necessary
If UBound(sChartSheetNames) < cChartSheets Then
ReDim Preserve sChartSheetNames(1 To cChartSheets + 5)
End If
' Save name of chart sheet
sChartSheetNames(cChartSheets) = ws.Name
' Add chart sheet name to list box
lstChartSheets.AddItem sChartSheetNames(cChartSheets)
Next
End Sub