Moderatori: Anthony47, Flash30005
Dim myFso As Object, ccAll As Long 'RIGOROSAMENTE IN TESTA AL MODULO
Function RecurDir(ByVal ccDir As String, myExt As Variant, ByRef cStore As Variant) As String
Dim myItm, mySplit, myInd
'
If myFso Is Nothing Then Set myFso = CreateObject("Scripting.FileSystemObject")
If myFso Is Nothing Then Beep
DoEvents
On Error GoTo Mahh
For Each myItm In myFso.GetFolder(ccDir).Files
ccAll = ccAll + 1
mySplit = Split(" " & myItm, ".", , vbTextCompare)
If Not IsError(Application.Match(mySplit(UBound(mySplit)), myExt, 0)) Then
myInd = UBound(cStore)
ReDim Preserve cStore(1 To myInd + 1)
cStore(myInd) = myItm
End If
Mahh:
Resume Bohh
Bohh:
Next myItm
For Each myItm In myFso.GetFolder(ccDir).SubFolders
Call RecurDir(myItm, myExt, cStore)
Next myItm
End Function
Sub MakeList()
Dim strFile As String, ShIndex As Worksheet
'' Dim stdPic As StdPicture
'' Dim lngWidth As Long
'' Dim lngHeight As Long
Dim strPath As String, mySplit
Dim intRow As Long, AllPics, StrDir As String, I As Long
'
Sheets("Foglio2").Select
Dim FArr() As String
ReDim FArr(1 To 1)
AllPics = Array("xls", "xlsx", "xlsm", "xlsb") '<<< Altri formati? '***
StrDir = "C:\PROVA\NUOVA" '<<< Il Percorso iniziale
Call RecurDir(StrDir, AllPics, FArr)
Range("A2").Resize(UBound(FArr), 1).Value = Application.WorksheetFunction.Transpose(FArr)
On Error Resume Next
Set myFso = Nothing
On Error GoTo 0
MsgBox ("Indice creato, " & UBound(FArr))
Debug.Print "Indice creato, " & UBound(FArr)
End Sub
Sub GodSaveTony()
Dim ShIndex As Worksheet, ModSh As Worksheet, LogSh As Worksheet
Dim lIndex As Long, I As Long, J As Long
Set ShIndex = ThisWorkbook.Sheets("Foglio2")
Set ModSh = ThisWorkbook.Sheets("Foglio1")
Set LogSh = ThisWorkbook.Sheets("Foglio3")
ShIndex.Select
Application.EnableEvents = False
For I = 1 To ShIndex.Cells(Rows.Count, 1).End(xlUp).Row
If ShIndex.Cells(I, 1) <> "" Then
lIndex = LogSh.Cells(Rows.Count, 1).End(xlUp).Row + 1
Workbooks.Open ShIndex.Cells(I, 1).Value
LogSh.Cells(lIndex, 1) = ShIndex.Cells(I, 1).Value
LogSh.Cells(lIndex, 2) = ActiveWorkbook.Name
If ActiveWorkbook.Name <> ThisWorkbook.Name Then
For J = 2 To ModSh.Cells(Rows.Count, 1).End(xlUp).Row
If LogSh.Cells(lIndex, 1) = "" Then LogSh.Cells(lIndex, 1) = Chr(34)
LogSh.Cells(lIndex, 3) = ModSh.Cells(J, 1)
LogSh.Cells(lIndex, 4) = ModSh.Cells(J, 2)
LogSh.Cells(lIndex, 5) = Sheets(ModSh.Cells(J, 1).Value).Range(ModSh.Cells(J, 2).Value).Value
LogSh.Cells(lIndex, 6) = ModSh.Cells(J, 3)
Sheets(ModSh.Cells(J, 1).Value).Range(ModSh.Cells(J, 2).Value).Value = ModSh.Cells(J, 3)
lIndex = lIndex + 1
Next J
End If
ShIndex.Cells(I, 2).Value = ShIndex.Cells(I, 1).Value
ShIndex.Cells(I, 1).ClearContents
Exit For
End If
Next I
Application.EnableEvents = True
Beep
End Sub
Si puo' andare da (1) una cosa "fa tutto la macro" (in questo caso sarebbe meglio avere qualche elemento per essere certi che stiamo per modificare uno dei file giusti, tipo un pezzo di NomeFile; se sono xls, xlsx, xlsm, o che cosa; il nome dei fogli). Oppure (2) la macro apre i file che trova uno dopo l'altro; tu fai quel che serve, chiudi il file, ripeti la macro.
Se sono meno di 10 file invece e' piu' semplice che (3) fai tutto a mano.
Sub GodSaveTonyLoop()
Dim ShIndex As Worksheet, ModSh As Worksheet, LogSh As Worksheet
Dim lIndex As Long, I As Long, J As Long
Dim cWb As Workbook, wCnt As Long '+++ Loop
'
Set ShIndex = ThisWorkbook.Sheets("Foglio2")
Set ModSh = ThisWorkbook.Sheets("Foglio1")
Set LogSh = ThisWorkbook.Sheets("Foglio3")
'
ShIndex.Select
Application.EnableEvents = False
For I = 1 To ShIndex.Cells(Rows.Count, 1).End(xlUp).Row
If ShIndex.Cells(I, 1) <> "" Then
lIndex = LogSh.Cells(Rows.Count, 1).End(xlUp).Row + 1
Workbooks.Open ShIndex.Cells(I, 1).Value
Set cWb = ActiveWorkbook '+++ Loop
LogSh.Cells(lIndex, 1) = ShIndex.Cells(I, 1).Value
LogSh.Cells(lIndex, 2) = ActiveWorkbook.Name
If ActiveWorkbook.Name <> ThisWorkbook.Name Then
For J = 2 To ModSh.Cells(Rows.Count, 1).End(xlUp).Row
If LogSh.Cells(lIndex, 1) = "" Then LogSh.Cells(lIndex, 1) = Chr(34)
LogSh.Cells(lIndex, 3) = ModSh.Cells(J, 1)
LogSh.Cells(lIndex, 4) = ModSh.Cells(J, 2)
LogSh.Cells(lIndex, 5) = Sheets(ModSh.Cells(J, 1).Value).Range(ModSh.Cells(J, 2).Value).Value
LogSh.Cells(lIndex, 6) = ModSh.Cells(J, 3)
Sheets(ModSh.Cells(J, 1).Value).Range(ModSh.Cells(J, 2).Value).Value = ModSh.Cells(J, 3)
lIndex = lIndex + 1
Next J
End If
ShIndex.Cells(I, 2).Value = ShIndex.Cells(I, 1).Value
ShIndex.Cells(I, 1).ClearContents
' Exit For '--- Loop
cWb.Close True '+++ Loop
wCnt = wCnt + 1 '+++ Loop
End If
Next I
Application.EnableEvents = True
Beep
MsgBox ("Completato, " & wCnt & " File")
End Sub
Torna a Applicazioni Office Windows
Ordinare colonne sulla stessa riga se stesso contenuto Autore: Ricky0185 |
Forum: Applicazioni Office Windows Risposte: 10 |
Inserire dati filtrati da 2 file ad un terzo file Autore: Ricky0185 |
Forum: Applicazioni Office Windows Risposte: 14 |
Inserire add.in nella barra di avvio veloce in excel 2003 Autore: Ricky0185 |
Forum: Applicazioni Office Windows Risposte: 4 |
File batch per copiare file selezionato da menu contestuale Autore: valle1975 |
Forum: Programmazione Risposte: 3 |
Visitano il forum: Nessuno e 61 ospiti