![]() |
open workbook
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. |
open workbook
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 -- If this post helps click Yes --------------- Jacob Skaria "Ranjith Kurian" wrote: 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. |
open workbook
thanks a lot
"Jacob Skaria" wrote: 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 -- If this post helps click Yes --------------- Jacob Skaria "Ranjith Kurian" wrote: 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. |
open workbook
Cheers..
If this post helps click Yes --------------- Jacob Skaria "Ranjith Kurian" wrote: thanks a lot "Jacob Skaria" wrote: 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 -- If this post helps click Yes --------------- Jacob Skaria "Ranjith Kurian" wrote: 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. |
open workbook
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 "Ranjith Kurian" wrote: 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. |
All times are GMT +1. The time now is 03:02 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com