Hi jeroen,
Thanks for the help. I think I didnt make my question clear. I do not want to open any file. Just want the code to get the value of a cell in every excel file in a directory. Basically need to automate some compilation work.
Something to the effect,
for <each excel in directory>
sum = sum + A4.value
next
Regards,
--Ankur.
Main Topics
Browse All Topics





by: roos01Posted on 2004-05-30 at 23:54:43ID: 11194628
Hi ankurk,
e(filefilt er:=Filt, _
perhaps this give you some ideas:
Sub OpenMultipleFiles()
Dim Filt As String, Title As String, Msg As String
Dim i As Integer, FilterIndex As Integer
Dim filename As Variant
' File filters
Filt = "Excel Files (*.xls),*.xls," & _
"Text Files (*.txt),*.txt," & _
"All Files (*.*),*.*"
' Default filter to *.*
FilterIndex = 3
' Set Dialog Caption
Title = "Select File(s) to Open"
' Set File Name Array to selected Files (allow multiple)
filename = Application.GetOpenFilenam
FilterIndex:=FilterIndex, Title:=Title, MultiSelect:=True)
' Exit on Cancel
If Not IsArray(filename) Then
MsgBox "No file was selected."
Exit Sub
End If
' Open Files
For i = LBound(filename) To UBound(filename)
Msg = Msg & filename(i) & vbCrLf ' This can be removed
Workbooks.Open filename(i)
Next i
MsgBox Msg, vbInformation, "Files Opened" ' This can be removed
End Sub
regards,
jeroen