Olá, tenho uma macro que abre a última planilha(pela data mais recente) da minha pasta, porém não funciona. Na teoria era pra ela estar puxando da minha pasta base a última planilha e abrindo, alguém poderia me ajudar? segue código da macro que estou utilizando
Sub AbrirRecentes()
'Abre o arquivo mais recente da pasta "base" (Último arquivo)
Dim MyPath As String
Dim MyFile As String
Dim LatestFile As String
Dim LatestDate As Date
Dim LMD As Date
'Encaminha usuário a pasta onde tem os arquivos "originais" que serão abertos e formatados
MyPath = "\\sad154000\Corporativo\Gepej\#NOVA_ESTRUTURA\Estagiarios\Álax\TaxaBacen\base"
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
MyFile = Dir(MyPath & "* .xls", vbNormal)
If Len(MyFile) = 0 Then
MsgBox "Nenhum arquivo foi encontrado …", 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
End Sub