
Tópicos relacionados:
Ao descarregar umas 700 fotos de uma câmera, também precisei renomeá-las. Pode imaginar como seria rápido fazer isso?
Percebi que alterá-las manualmente, não era algo que estava interessado em fazer, então eu debrucei-me sob o VBA para resolver-me este "problema".
Este código percorrerá uma pasta e renomeará todos os arquivos nela.
Function ReFileName (Prefix As String, _FILEPATH As String, _nExtension As String, _FinalExtension As String)Dim strfile As StringDim filenum As StringDim SizeExtension As IntegerLet strfile = Dir(FILEPATH)Let SizeExtension = Len(Replace(nExtension, ".", ""))Do While strfile <> ""Debug.Print strfileIf Right$(strfile, SizeExtension) = nExtension ThenLet filenum = Mid$(strfile, Len(strfile) - 6, SizeExtension)Name FILEPATH & strfile As FILEPATH & Prefix & filenum & "." & FinalExtensionEnd IfLet strfile = DirLoopEnd Function
Tags: VBA, file, rename, folder, pasta, tips