I spent all day trying to understand VBA and I tried so many different websites to find the right code, but i just cant make it work. The code i am using right now imports all the worksheets on all the excel files I have on my folder. I only need to import the most recent one. I added a command button with it just as suggested in the website where i got this code. In the long run i would like to be able to apply the data imported to a table i already have on the main worksheet, following by printing the template and then deleting the information so i can start over with the next recent spreadsheet. BUT for now i only want to know how to get ONLY the most recent file imported to my worksheet.
Private Sub CommandButton1_Click()
Dim directory As String, fileName As String, sheet As Worksheet, total As Integer
directory = "C:\ExcelPract\"
fileName = Dir(directory & "*.xl??")
Do While fileName <> ""
Workbooks.Open (directory & fileName)
For Each sheet In Workbooks(fileName).Worksheets
total = Workbooks("Docket .xls").Worksheets.count
Workbooks(fileName).Worksheets(sheet.Name).Copy _
after:=Workbooks("Docket .xls").Worksheets(total)
Next sheet
Workbooks(fileName).Close
fileName = Dir()
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub