Using macros to open 10 files?

MACROSCRIBER

New Member
Joined
Dec 16, 2005
Messages
8
How do I select open and close 10 excel files indivualy and sequentially
perhaps they would be file 1 file2 file3.......?
 

Some videos you may like

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,086
Office Version
  1. 365
Platform
  1. Windows
Like this perhaps.
Code:
Dim wb As Workbook

For I = 1 To 10
     Set wb = Workbooks.Open(Filename:="C:\File" & I & ".xls)

     ' do stuff with workbook here

     wb.Close

Next I
 

MACROSCRIBER

New Member
Joined
Dec 16, 2005
Messages
8
almost there

thanks for the code but the set line buggs out when i try to runit
heres is how i can write my idea for 3 files instead on 10


a$(1)="file1.xls"
a$(2)="file2.xls"
a$(3)="file3.xls"

for n=1to3

open excel file a$(n)

do other macro stuff here

close excel file a$(n)

next n


how would i do this with vba macros?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,086
Office Version
  1. 365
Platform
  1. Windows
How does the code 'bug' out?

It's only really an example and would have to be adapted for your particular situation.
 

Watch MrExcel Video

Forum statistics

Threads
1,119,128
Messages
5,576,253
Members
412,709
Latest member
Rishu
Top