Здравствуйте, я использую функцию, которая вызывает самый последний файл в моей папке.Мне нужно автоматизировать vlookup для файла.У меня проблемы с правильным вызовом файла
Я уже пытался вызвать его по его пути, но мне кажется, что я его не правильно назвал.
Sub oversub()
'Newest file function
Dim MyPath As String
Dim MyFile As String
Dim LatestFile As String
Dim LatestDate As Date
Dim LMD As Date
MyPath = "C:\Users\TAmon1\Desktop\OverSubscription Dash"
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
MyFile = Dir(MyPath & "*.csv", vbNormal)
If Len(MyFile) = 0 Then
MsgBox "No files were found...", vbExclamation
Exit Sub
End If
Do While Len(MyFile) > 0
LMD = FileDateTime(MyPath & MyFile)
If LMD > LatestDate Then
LatestFile = MyFile
LatestDate = LMD
End If
MyFile = Dir
Loop
Workbooks.Open MyPath & LatestFile
Dim wb As Workbook
'wbstring = MyPath & LatestFile
Windows("Planning_tool.xlsm").Activate
'Vlookupfunction
Range("N2").Select
ActiveCell.FormulaR1C1=VLOOKUP(C[-13],'Router_level_crosstab.csv'!C1:C11,11,FALSE)"
В настоящее время я вызываю прямой файл, который работает, но когда у меня есть новый файл, мне нужно будет вручную изменить имя файла.Мне нужно включить последний файл в Vlookup.