draleo laid this down on his screen :
> Si. anche la procedura di vittorio funzionava; ero io ad aver sbagliato il
> copia incolla. Anche le spartane versioni di Bruno ora funzionano senza
> problemi. Rimane in sospeso la sub di Norman per rinominare le cartelle
Mi pare tu abbia a disposizione tre camerieri di prim'ordine,
vorrei vederti prodigo di laute mance.
Questa elenca i file di una determinata directory
(la DIR si può eventualmente definire con FileDialog)
=============================================
Sub ListFiles_1()
Dim FSO As Scripting.FileSystemObject, FsoFolder As Scripting.Folder
Dim FolderName As String, SheetName As String, i
FolderName = "D:\Dichiarazioni\2011 - Redditi 2010"
' Delete SheetName if exists and create a new one
SheetName = Mid(FolderName, InStrRev(FolderName, "\") + 1)
For Each i In ThisWorkbook.Sheets
If i.Name = SheetName Then
i.Delete
End If
Next
ThisWorkbook.Sheets.Add(After:=Sheets(Sheets.Count)).Name = SheetName
Range("A1").Value = "Full Path"
Range("B1").Value = "Filename"
Range("C1").Value = "Ext"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set FsoFolder = FSO.GetFolder(FolderName)
Call RecursiveFile_1(FsoFolder)
Columns.AutoFit
End Sub
Sub RecursiveFile_1(objFolder As Scripting.Folder)
Dim j As Long, i
j = Cells(Rows.Count, "A").End(xlUp).Row + 1
For Each i In objFolder.Files
Cells(j, "A") = Left(i.Path, InStrRev(i.Path, "\") - 1) & "\"
Cells(j, "B") = Mid(i.Path, InStrRev(i.Path, "\") + 1,
Len(Mid(i.Path, InStrRev(i.Path, "\"))) - Len(Mid(i.Path,
InStrRev(i.Path, ".") - 1)))
Cells(j, "C") = Right(i.Path, Len(i.Path) - InStrRev(i.Path, ".") +
1)
j = j + 1
Next
End Sub
=============================================
Questa rinomina i file elencati secondo quanto definito
in colonna D
===========================================
Public Sub RenameFiles_1()
Dim SourceRange As Range, i
Set SourceRange = Sheets("2011 - Redditi 2010").Range("A2")
Set SourceRange = Range(SourceRange, SourceRange.End(xlDown))
For Each i In SourceRange
Name i & i(1, 2) & i(1, 3) As i & i(1, 4) & i(1, 3)
Next
End Sub
===========================================
Bruno