Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
Por leoRaposo
#33148
Gostaria de solucionar uma duvida com relação à excluir arquivos em uma pasta..
Sei que a função Kill apaga todos os arquivos de uma pasta..
Ex.: Kill "C:\Users\Leandro.Ferreira\Desktop\Nova pasta\*"
Mas gostaria de uma formula que exclua apenas 1 (um) arquivo por vez (Já que nesta pasta possuem vários outros arquivos).
De preferencia o mais recente da pasta.
Podem me ajudar ?
Por babdallas
#33184
Tente isso
Código: Selecionar todos
Option Explicit
'Código de OsvaldoMp em outro fórum. Adaptado por Bruno Abdalla de Souza (babdallas)
'para uma dúvida do Fórum do Guru do Excel em 20/05/2018
Sub DeletaArquivoMaisRecente()
    Dim arqSys As Object
    Dim objArq As Object
    Dim minhaPasta
    Dim nomeArq As String
    Dim dataArq As Date
    Dim strLinkAtual As String
          Const Diret As String = "C:\Users\Bruno\Desktop"
          Set arqSys = CreateObject("Scripting.FileSystemObject")
          Set minhaPasta = arqSys.GetFolder(Diret)
          dataArq = DateSerial(1900, 1, 1)
    For Each objArq In minhaPasta.Files
        If objArq.Path <> ThisWorkbook.FullName And Left(objArq.Path, 1) <> "~" Then
            If objArq.DateLastModified > dataArq Then
                dataArq = objArq.DateLastModified
                nomeArq = objArq
            End If
        End If
    Next objArq
    
    Kill objArq
End Sub
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord