Open excel file through macro

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.
 
B

Bernie Deitrick

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
 
D

Daniel Haley

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

In principal this should be pretty easy.
 

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