ItalianPlatinum
Well-known Member
- Joined
- Mar 23, 2017
- Messages
- 795
- Office Version
- 365
- 2019
- Platform
- Windows
I have a VBA code that works like a charm that displays a dialog box and allows a user to select a file. I am trying to enhance it to force the file to be opened based off a set criteria. For example, the file format is AAA_20200529_0513. So a file will be saved daily with AAA_ then the date in YYYYMMDD then _ and time in HHMM. I really only care about the date it was saved and the file name so. AAAA_YYYYMMDD is met. So anyway to force the file that is opened to meet that criteria, and if it doesnt exist to kick out an error message?
Sub OpenCopyTXT()
Dim Fname As String
With Application.FileDialog(3)
.InitialFileName = "C:\Windows"
.Filters.Add "Text Files Only", "*.txt"
If .Show = -1 Then Fname = .SelectedItems(1)
End With
Workbooks.OpenText Fname
End Sub
Sub OpenCopyTXT()
Dim Fname As String
With Application.FileDialog(3)
.InitialFileName = "C:\Windows"
.Filters.Add "Text Files Only", "*.txt"
If .Show = -1 Then Fname = .SelectedItems(1)
End With
Workbooks.OpenText Fname
End Sub