Hi all,
I am trying to populate a array(40,1) with text data in the first column of a closed book ("CAC40.xls"). I built something fromn some codes I found,, but I have a "mismatch" problem on the line myarray(x, y) = GetData(FilePath, FileName, SheetName, Address)
Has anyone an idea ?
Thanks
I am trying to populate a array(40,1) with text data in the first column of a closed book ("CAC40.xls"). I built something fromn some codes I found,, but I have a "mismatch" problem on the line myarray(x, y) = GetData(FilePath, FileName, SheetName, Address)
Has anyone an idea ?
Thanks
Code:
Sub GetDataDemo()
Dim FilePath$, Row&, Column&, Address$
'change constants & FilePath below to suit
'***************************************
Const FileName$ = "CAC40.xls"
Const SheetName$ = "Sheet1"
Const NumRows& = 40
Const NumColumns& = 1
FilePath = "H:\Outlook\"
'***************************************
DoEvents
Excel.Application.ScreenUpdating = False
If Dir(FilePath & FileName) = Empty Then
MsgBox "The file " & FileName & " was not found", , "File Doesn't Exist"
Exit Sub
End If
Dim myarray(NumRows, NumColumns) As Long
Dim x As Long
Dim y As Long
For x = 1 To NumRows
For y = 1 To NumColumns
Address = Cells(x, y).Address
myarray(x, y) = GetData(FilePath, FileName, SheetName, Address)
Next y
Next x
ActiveWindow.DisplayZeros = False
End Sub
Private Function GetData(Path, File, Sheet, Address)
Dim Data$
Data = "'" & Path & "[" & File & "]" & Sheet & "'!" & _
Range(Address).Range("A1").Address(, , xlR1C1)
GetData = ExecuteExcel4Macro(Data)
End Function