Open excel file through macro

  • Thread starter Thread starter Gaurav.alw
  • Start date Start date
G

Gaurav.alw

I have one excel file with a column for file names and its entire path
written into it. Is there any code through which i can open those
file, read some data and close that file.
 
Sub OpenBooks()
Dim myC As Range
Dim myB As Workbook
Dim myData As Variant

For Each myC In Range("A2:A100")
Set myB = Workbooks.Open(myC.Value)
'Read your data
myData = myB.Sheets(1).Range("A2").Value
'Do something with your data - write it next to the workbook name
myC(1,2).Value = myData
myB.Close False
Next myC
End Sub

But there is no need to open the workbooks to read data - you could just
link to the cells....

HTH,
Bernie
MS Excel MVP
 
Are those files also Excel files? If so, what type of data are you
trying to retrieve.

In principal this should be pretty easy.
 
Back
Top