open workbook

R

Ranjith Kurian

I have created a macro code to formate my excel file below is the code

sub test()
ChDir "C:\N"
Workbooks.Open Filename:="C:\N\AU.xls"
Rows("1:1").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
End sub

The above code work only in file AU.xls, i would like to have a short macro
code to open my other three files (BU.xls, DU.xls, EF.xls) and perform the
same action to it.

Is it possible to put the formate part in loop.
 
J

Jacob Skaria

Try this untested code....

Sub test()

Dim intTemp As Integer
Dim arrWorkBook As Variant

arrWorkBook = Array("AU.xls", "BU.xls", "DU.xls", "EF.xls")

For intTemp = 0 To UBound(arrWorkBook)
Workbooks.Open Filename:="C:\N\" & arrWorkBook(intTemp)
Rows("1:1").Select
With Selection.Interior
..ColorIndex = 6
..Pattern = xlSolid
End With
Next
End Sub
 
R

Ranjith Kurian

thanks a lot

Jacob Skaria said:
Try this untested code....

Sub test()

Dim intTemp As Integer
Dim arrWorkBook As Variant

arrWorkBook = Array("AU.xls", "BU.xls", "DU.xls", "EF.xls")

For intTemp = 0 To UBound(arrWorkBook)
Workbooks.Open Filename:="C:\N\" & arrWorkBook(intTemp)
Rows("1:1").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Next
End Sub
 
M

Mike H

Try this

Sub test()
BookData = "BU.xls,DU.xls,EF.xls"
MyBook = Split(BookData, ",")
For x = 0 To UBound(MyBook)
Workbooks.Open Filename:="C:\N\" & MyBook(x)
ActiveSheet.Rows("1:1").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
ActiveWorkbook.Close savechanges:=True
Next
End Sub

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top