ItalianPlatinum
Well-known Member
- Joined
- Mar 23, 2017
- Messages
- 880
- Office Version
- 365
- 2019
- Platform
- Windows
Hello - I am looking for a way to open a file that is the most recent. I have code to open the file if it is a partial file but I have a new issue where there are two versions that were saved and just want the most recent one opened. Is someone able to assist? I would like to use the below still cause it is embedded all over my macro
VBA Code:
Function OpenCopyST() As Boolean
Dim sPath As String
Dim sPartial As String
Dim sFName As String
sPath = "\\xxxxxx\xxxx$\xxxx\xxxx\xxx xxxx\" ' <<<<< change accordingly
sPartial = "vi_j_dt_dist_" & Year(Now) & IIf(Len(Month(Now)) = 1, "0" & Month(Now), Month(Now)) & IIf(Len(Day(Now)) = 1, "0" & Day(Now), Day(Now)) & "*.txt"
sFName = Dir(sPath & sPartial)
If Len(sFName) > 0 Then
Workbooks.OpenText sPath & sFName, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
Array(7, 1), Array(8, 2)), TrailingMinusNumbers:=True
OpenCopyST = True
Else
OpenCopyST = False
End If
End Function