filmov
tv
Excel VBA Macro: Open Newest File (In User Selected Folder)
Показать описание
Excel VBA Macro: Open Newest File (In User Selected Folder). In this video, we go over how to automatically find and open the latest file in a user selected folder.
Code (YouTube doesn't allow brackets; so LT and GT are used for less than and greater than, respectively):
Sub newest_file_in_folder()
Dim FldrPicker As FileDialog
Dim myPath As String
Dim myFile As String
Dim newestFile As String
Dim newestDate As Date
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Please Select Folder"
.AllowMultiSelect = False
.ButtonName = "Confirm"
If .Show = -1 Then
myPath = .SelectedItems(1) & "\"
Else
End
End If
End With
myFile = Dir(myPath)
newestFile = myFile
On Error GoTo noFiles
newestDate = FileDateTime(myPath & myFile)
Do While myFile LTGT ""
If FileDateTime(myPath & myFile) GT newestDate Then
newestFile = myFile
newestDate = FileDateTime(myPath & myFile)
End If
myFile = Dir
Loop
Workbooks.Open Filename:=myPath & newestFile
End
noFiles:
MsgBox "There are no items in this folder."
End Sub
#ExcelVBA #ExcelMacro
Code (YouTube doesn't allow brackets; so LT and GT are used for less than and greater than, respectively):
Sub newest_file_in_folder()
Dim FldrPicker As FileDialog
Dim myPath As String
Dim myFile As String
Dim newestFile As String
Dim newestDate As Date
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Please Select Folder"
.AllowMultiSelect = False
.ButtonName = "Confirm"
If .Show = -1 Then
myPath = .SelectedItems(1) & "\"
Else
End
End If
End With
myFile = Dir(myPath)
newestFile = myFile
On Error GoTo noFiles
newestDate = FileDateTime(myPath & myFile)
Do While myFile LTGT ""
If FileDateTime(myPath & myFile) GT newestDate Then
newestFile = myFile
newestDate = FileDateTime(myPath & myFile)
End If
myFile = Dir
Loop
Workbooks.Open Filename:=myPath & newestFile
End
noFiles:
MsgBox "There are no items in this folder."
End Sub
#ExcelVBA #ExcelMacro
Excel VBA Macro: Open Newest File (In User Selected Folder)
VBA to Create New Workbook - Excel VBA Macro Example
Excel VBA To Open & Import Last Created/ Most Recent Workbook in Folder
VBA/Macro Course - 3 Ways to Create New Workbooks & Save and Close Them Using a Macro
VBA Active Workbook, This Workbook, Name, Path and Renaming a Workbook (Code Included)
VBA Create a new Excel file from template
VBA Code to Add New Sheet and Rename - Excel VBA Example by ExcelDestination
Excel VBA Macro: Create Word Document (and Write with Excel)
How To Create A Simple Personal Wealth Manager In Excel – FROM SCRATCH + FREE TEMPLATE
Excel VBA Macro: Autofilter, Copy, Paste to New Sheet and Save to Specified Location (Dynamic Range)
How to Start Using VBA | Enable Visual Basic in Excel | Get Developer Tab | Programming in Excel
Excel VBA - How To Open Another Workbook
Excel VBA - Write a Simple Macro
Excel VBA: Create New Worksheet For EACH UNIQUE ITEM in List & Copy Record
How to open an excel file from a folder using VBA / Macro | I'm MS Excel Expert Tutorial | Day ...
VBA Macro to Copy Data from Another Workbook in Excel
Excel VBA Open File and Copy to Workbook
Excel VBA - Workbook Open
Excel VBA Macro Save .xlsm File to Specific Location as .xlsx | File Name Based on Cell Values
Easy VBA File Selection Window to Open Files in Excel
Excel VBA - Save a Macro Workbook
VBA to Get the File Path and folder path - VBA for file picker and folder picker
Excel VBA - Copy worksheet to a new workbook and rename
How to Create Macros in Excel Tutorial
Комментарии