Extracting values from latest closed workbook into current workbook?
Hi, having some challanges extracting values from latest workbook. Files in "C:\" have files where filenames are dates and on a weekly bases the files in this folder change. So basically the file "062215_L01.xls" will change to "062915_L01.xls" next week. I would like to get data from the latest _L01 file. Is there a way around this? Thanks
Sub ExtractDataEleven()
Dim X As Long
Dim FilePath$, Row&, Column&, Address$
Const FileName$ = "062215_L01.xls" <---This file should be the latest date
Const SheetName$ = "_L01"
Const NumColumns& = 40
Const NumRows& = 100
FilePath = ("C:\")
X = 0
DoEvents
Application.ScreenUpdating = False
If Dir(FilePath & FileName) = Empty Then
MsgBox "The file " & FileName & " was not found", , "File Doesn't Exist"
Exit Sub
End If
With Worksheets("L1")
For Row = 1 To NumRows
For Column = 1 To NumColumns
Address = .Cells(Row, Column).Address
.Cells(Row, Column + X) = GetDataEleven(FilePath, FileName, SheetName, Address)
Next Column
Next Row
.Columns.AutoFit
End With
ActiveWindow.DisplayZeros = False
End Sub
Private Function GetDataEleven(Path, File, Sheet, Address)
Dim Data$
Data = "'" & Path & "[" & File & "]" & Sheet & "'!" & _
Range(Address).Range("A1").Address(, , xlR1C1)
GetDataEleven = ExecuteExcel4Macro(Data)
End Function
Bookmarks