Excel VBA Macro: Open Newest Files (from Multiple Folders) and Save Them in Another Folder

  Рет қаралды 2,321

greggowaffles

greggowaffles

2 жыл бұрын

Excel VBA Macro: Open Newest Files (from Multiple Folders) and Save Them in Another Folder. In this video, we create code that checks a list of folders, pulls the latest file out of each one, and saves them all to another specified folder.
Code (KZbin doesn't allow brackets; so LT and GT are used for less than and greater than, respectively):
Sub save_newest_files_to_folder()
Dim myPath As String
Dim myFile As String
Dim destination As String
Dim newestFile As String
Dim newestDate As Date
Dim fldr_count As Integer
Dim ws As Worksheet
Dim i As Integer
Dim check As Integer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set ws = ThisWorkbook.Sheets("Sheet1")
fldr_count = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlDown)))
destination = ws.Cells(2, 2).Text & "\"
For i = 2 To fldr_count
check = 0
myPath = ws.Cells(i, 1).Text & "\"
myFile = Dir(myPath)
newestFile = myFile
On Error GoTo noFiles
newestDate = FileDateTime(myPath & myFile)
Do While myFile LT GT ""
check = 1
If FileDateTime(myPath & myFile) GT newestDate Then
newestFile = myFile
newestDate = FileDateTime(myPath & myFile)
End If
myFile = Dir
Loop
Workbooks.Open Filename:=myPath & newestFile
ActiveWorkbook.SaveAs Filename:=destination & newestFile
ActiveWorkbook.Close
noFiles:
If check = 0 Then
MsgBox "There are no files in this folder: " & myPath
End If
Next i
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
#ExcelVBA #ExcelMacro

Пікірлер: 8
@geraldzhang8743
@geraldzhang8743 2 жыл бұрын
Appreciate your work. I actually learned a lot from you. Your videos are so different than other KZbinr. I wish you can make more videos later soon.
@greggowaffles
@greggowaffles 2 жыл бұрын
Thank you so much!! I’ll start making them again soon
@miraabel7012
@miraabel7012 6 ай бұрын
Will you please help modify your VBA code to find files from a list ( column 1, those will be paths to multiple folders etc) and save all in one destination folder. Thank you
@naomifagan2885
@naomifagan2885 2 жыл бұрын
And if you have any ideas on macro for creating reoccurring action plan list for tasks that occur monthly
@dhirendranathmandal6949
@dhirendranathmandal6949 2 жыл бұрын
Please make a video for VBA to Save a specific Excel sheet using data from cells & single click
@shubhamyadav-nd4zx
@shubhamyadav-nd4zx 2 жыл бұрын
Help me to make a VBA code to send 20 files. Just like you did it need to add up a little bit more. Let me give details a little bit. Each mail has a different attachment and mail body. Like if I am sending my 1st mail. I will open that excel file, go to a particular sheet, copy data, paste it to the email body, and attach that same file as an attachment. Once the mail is ready then that file gets closed. And then with 2nd mail and it will go on for 19 times.
@naomifagan2885
@naomifagan2885 2 жыл бұрын
Hi, Can you please do some videos on the following Creating new worksheet for each day of the month automatically only show that sheet for specific day and have a workbook for each month with all the data Copying specific columns from different workbooks to one workbook sheet
@greggowaffles
@greggowaffles 2 жыл бұрын
Will do! Thanks!!
Excel VBA Macro: Autofilter And Copy to New Workbook (Dynamic Range)
14:08
Playing hide and seek with my dog 🐶
00:25
Zach King
Рет қаралды 34 МЛН
Женская драка в Кызылорде
00:53
AIRAN
Рет қаралды 488 М.
Задержи дыхание дольше всех!
00:42
Аришнев
Рет қаралды 3,6 МЛН
Sigma girl and soap bubbles by Secret Vlog
00:37
Secret Vlog
Рет қаралды 14 МЛН
Excel VBA Macro: Open Newest File (In User Selected Folder)
10:24
greggowaffles
Рет қаралды 2,5 М.
Excel VBA Macro: List All Files (From a Selected Folder)
8:43
greggowaffles
Рет қаралды 9 М.
VBA to BROWSE & COPY Data from SELECTED File in Excel
10:00
Leila Gharani
Рет қаралды 324 М.
Loop Through Subfolders of a Folder using Excel VBA
6:51
Computergaga
Рет қаралды 14 М.
AWESOME Excel trick to combine data from multiple sheets
7:27
Playing hide and seek with my dog 🐶
00:25
Zach King
Рет қаралды 34 МЛН