Macro to open 215 Workbooks and get data from them

stathisaska

New Member
Joined
May 1, 2014
Messages
8
Dear all,

I want to import data from 215 workbooks formatted the same way.
I have created a summary workbook which contains all filenames in A1:A215

I have created a macro to open all which it is like this

Code:
Sub open_all()
Dim filenames(215) As String
Dim time1 As Date
Dim time2 As Date


time1 = Now


    
    For i = 1 To 215
        filenames(i) = "/Users/soldier/Library/Containers/com.microsoft.Excel/Data/files/" & Cells(i, 1).Value
    Next


MsgBox ("Filenames copied")


Dim WB As Workbook


    For i = 1 To 10
    Set WB = Workbooks.Open(filenames(i))
    Next


time2 = Now


msgbox(time2-time1)


End Sub

It takes 8 seconds to open 10 workbooks. I tried more and more, but for 215 it stuck.

I am running an iMac with a fusion drive and those specifications:
Processor Name: Intel Core i5
Processor Speed: 3,2 GHz
Number of Processors: 1
Total Number of Cores: 4
L2 Cache (per Core): 256 KB
L3 Cache: 6 MB
Memory: 8 GB

The workbooks have a total of 35mb


My questions:



  1. Do you believe this task it's not possible ?
  2. Can I import data without even opening workbooks
  3. Can i open workbooks and keep them hidden
  4. Shall I open workbooks 1 by 1: get the information I need, close the workbook and then proceed to next one
  5. Would you recommend any other method to get the outcome I need ?
 
Last edited:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi, Put all of your workbooks in a folder. And open A workbook for import data from those Workbooks.

paste this code below.

Code:
Sub FromAllWorkbooks()
Application.DisplayAlerts = False
Application.ScreenUpdating = False

Dim WB As Workbook 

Dim path As String

Dim Wbooks As String 

path = "Your Workbooks FilePath\"

dont forget to put \ end of your file path.


Code:
Wbooks = Dir(path & "*.xlsx") 

Do While Wbooks<> "" 

Set WB= Workbooks.Open(path& Wbooks)
 Range(Range("a2"), Range("a100000").End(xlUp).End(xlToRight)).Copy

Range("a1").CurrentRegion.Copy


After you copy the data, activate the other workbook, paste the data, close the workbook,
switch to other workbook until all the workbooks will be runned

Code:
Workbooks("YourConsolidationWorkbookName").Activate 

Range("a100000").End(xlUp).Offset(1, 0).PasteSpecial (xlPasteAll)

WB.Close 
Wbooks= Dir()
Loop
End Sub


Or you can use Power Query :)
 
Last edited:
Upvote 0
Why do you need VBA for this?

You could put a formula together that will do what you want.
You *could* use INDIRECT(), but the other file/s need to be open, but if this is a constant process with the same files always being used, you could take some time and set up the formulas to reference each WB
 
Upvote 0
Do not open all the workbooks at the same time.

Open a workbook, get the data from it, close it and move onto the next workbook.
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,387
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top