I am trying to add a filter to only select the most recent file to import, but am stuck. Does anyone know how to achieve this?
Sub opname1()
Const toFind = ".log"
Dim vpath As String
Dim vfile As String
Dim curTxt As Workbook
vpath = "C:\Users\test\Desktop\test"
vfile = Dir(vpath & "*" & toFind)
Do While vfile <> ""
Set curTxt = Workbooks.Open(vpath & vfile)
curTxt.Worksheets(1).Columns(1).TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
Semicolon:=True, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2))
With curTxt.Worksheets(1)
.Range("f1").Formula = "=b1&"";""&c1"
.Range("f1").AutoFill Destination:=.Range("F1").Resize(WorksheetFunction.CountA(.Range("A:A")), 1)
.Range("F:F").Copy
.Range("B:B").PasteSpecial xlPasteValues
.Range("C:C").Delete
.Range("E:E").Delete
End With
curTxt.Worksheets(1).Move after:=ThisWorkbook.Worksheets(1)
vfile = Dir
Loop
Sub opname1()
Const toFind = ".log"
Dim vpath As String
Dim vfile As String
Dim curTxt As Workbook
vpath = "C:\Users\test\Desktop\test"
vfile = Dir(vpath & "*" & toFind)
Do While vfile <> ""
Set curTxt = Workbooks.Open(vpath & vfile)
curTxt.Worksheets(1).Columns(1).TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
Semicolon:=True, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2))
With curTxt.Worksheets(1)
.Range("f1").Formula = "=b1&"";""&c1"
.Range("f1").AutoFill Destination:=.Range("F1").Resize(WorksheetFunction.CountA(.Range("A:A")), 1)
.Range("F:F").Copy
.Range("B:B").PasteSpecial xlPasteValues
.Range("C:C").Delete
.Range("E:E").Delete
End With
curTxt.Worksheets(1).Move after:=ThisWorkbook.Worksheets(1)
vfile = Dir
Loop