View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default File name to Cell

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)
With Rows("1:1").Interior
.ColorIndex = 6
.Pattern = xlSolid
End With

Select Case Left$(activeworkbokk.Name, 2)

Case "AU": Cells(intTemp + 1, "A").Value = "Australia"
Case "BU": Cells(intTemp + 1, "A").Value = "Burma"
Case "DU": Cells(intTemp + 1, "A").Value = "Dubai"
Case "EF": Cells(intTemp + 1, "A").Value = "EF???"
End Select
Next
End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Ranjith Kurian" wrote in message
...
Hi

I have used the below code to open each workbook and format , now is it
possible to add a macro code so that it should add the workbook file name
to
cell A2

example: if the file name is AU.xls then in same file in Cell A1 the name
should come as Austrila, and if the file name is BU.xls then in same file
Cell A1 the name should come as Burma etc..


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