Link to home
Start Free TrialLog in
Avatar of PJ0302917
PJ0302917

asked on

Stuck trying to get data out of closed Workbooks using FSO into a 2d Array

I have approx 10 Excel Files (XLSM) in a folder and want to access each Workbooks ("Data") sheet and copy the data into a 2d array. So in the end i will have 10 2d variant arrays. I do not want to open each workbook during this process and the below code has got me started but i've hit a road block trying to get the data from the Workbooks into an Array

So far im using the following code
Sub GetData()
    Dim fso As Object, fldStart As Object
    Dim MyPath As String, MyData As Variant
    
    Application.ScreenUpdating = False
    
    MyPath = "C:\Users\Desktop\XL Test"

    Set fso = CreateObject("scripting.FileSystemObject")
    Set fldStart = fso.GetFolder(MyPath)
    
    For Each f In fldStart.Files
        If f.Name Like "*.xl*" Then
           
'*** I Need code to give focus to each particular workbook
'*** I was pointed to an answered question on a forum where the user wanted something similar. (Below)

'*** Range("A1:A" & MaxRows).Formula = "=INDEX('" & MyPath & "\[" & f.Name & "]Sheet1'!AD:AD,ROW())"

'*** This does get me some data from each Workbook but I don't understand what alot of what it does
'*** The range i'm trying to use for each f will be along the lines of, start at A1, go to the last populated row. Then go right till the last populated column in row 1 

  
    End If
            
    Next f
       
End Sub

Open in new window


Can you help get me past this blocker, thanks
ASKER CERTIFIED SOLUTION
Avatar of Shums Faruk
Shums Faruk
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PJ0302917
PJ0302917

ASKER

Hi Shums

Thank you for the help, i'm just working through it now, at the moment the Workbooks are opening using the Set SrcWB = Application.Workbooks.Open(MyPath & FileName) line. Is it possible to have this happen in the background? (not visible to the user?)

Thanks

Pete
Hi Peter,

It will open at the background and you wouldn't even notice.
Thanks Shums. Really happy with you're solution and i've managed to extract the data i needed out of the other workbooks. Thanks again
You're Welcome Peter! Glad I was able to help.