
Sub Trova()
Dim R, Percorso, Ricerca
Percorso = Range("A1") ' in A1 inserire da dove deve iniziare la ricerca es. CDocumenti
Ricerca = Range("B1") ' In B1 inserire l'estensione dei file da cercare es: pdf
Columns("A:E").ClearContents
Range("A1") = Percorso
Range("B1") = Ricerca
With Application.FileSearch
.LookIn = Percorso
.SearchSubFolders = True
.Filename = Ricerca
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
Range("F1") = "sono stati trovati " & .FoundFiles.Count & " file(s)"
For R = 1 To .FoundFiles.Count
Cells(R + 1, 6) = .FoundFiles(R)
Percorso = .FoundFiles(R)
NomeFile = Right(Percorso, Len(Percorso) - InStrRev(Percorso, ""))
Nomepercorso = Left(Percorso, Len(Percorso) - Len(NomeFile) - 1)
Cells(R + 1, 3) = Nomepercorso
Cells(R + 1, 4) = NomeFile
Next
Else
MsgBox "Nessun file trovato"
End If
End With
End Sub |
Private Sub Sfoglia_Files()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''' ATTENZIONE RICHIEDE L'ATTIVAZIONE DELLA LIBRERIA MICROSOFT SCRIPTING RUNTIME '''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' Per l'attivazione andare su "Strumenti", "Riferimenti", cercare e spuntare il nome ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim strPath As String
Dim fd As FileDialog
Dim objfd As Variant
Dim objFSY As FileSystemObject
Dim objFOL As Folder
Dim objFIL As File
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.InitialFileName = "C:"
.Title = "Sfoglia cartelle"
.ButtonName = "Ok"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewDetails
.Show
For Each objfd In .SelectedItems
strPath = objfd
Next objfd
End With
If strPath = "" Then GoTo Uscita
Set objFSY = New FileSystemObject
Set objFOL = objFSY.GetFolder(strPath)
For Each objFIL In objFOL.Files
Debug.Print "NOME: " & objFIL.Name, "DIMENSIONE: "; objFIL.Size & " Byte" 'o altre azioni da fare sui files
Next
Uscita:
Set objFSY = Nothing
Set objFOL = Nothing
Set fd = Nothing
End Sub
|
Public Sub Sfoglia_Files() 'oppure semplicemente Sub Sfoglia_Files() |
Debug.Print |
Dimensioni = FileLen(Percorso) ' Restituisce la lunghezza del file (byte) Cells(R + 1, 5) = Dimensioni |
Select Case Right(nomefile, 4)
Case Is = ".jpg", ".GIF", ".PNG", ".BMP"
'faccio l'analisi del file, dimensione ecc
Case Else
End Select |
Sub dirdettagliata(cart, nome, este, confr)
'per Excel 2003
Dim objFSO As Object, objFile As Object
Dim finepath As String, altrofile As String
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set fs = Application.FileSearch
With fs
.NewSearch
.LookIn = cart
.SearchSubFolders = True
.Filename = nome & "." & este
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
For i = 1 To .FoundFiles.Count
On Error Resume Next
questofile = .FoundFiles(i) 'nomefile
Set objFile = objFSO.GetFile(questofile)
finepath = Mid(objFile.Path, Len(cart) + 1, 300)
ActiveCell.Value = finepath
ActiveCell.Offset(0, 1).Value = objFile.Size 'dimensioni
ActiveCell.Offset(0, 2).Value = objFile.DateLastModified 'modifica
ActiveCell.Offset(0, 3).Value = GetAttr(objFile) 'attributo A
If confr <> 0 Then
altrofile = Dir(confr & finepath)
If altrofile = "" Then
ActiveCell.Offset(0, 4).Value = "unico qui"
End If
End If
ActiveCell.Offset(1, 0).Select
Next i
Else
MsgBox "File(s) non trovato."
End If
End With
Set fs = Nothing
End Sub
Sub finepath()
inizioperc = Range("perc1").Value
finepath = Mid(objFile.Path, Len(inizioperc) + 1, 300)
End Sub
Sub MyInfoFile_Gab53()
'dettagli di un file
Dim objFSO As Object
Dim objFile As Object, inizioperc As String, finepath As String
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(Range("A1").Value)
inizioperc = Range("A2").Value
finepath = Mid(objFile.Path, Len(inizioperc) + 1, 300)
With Worksheets("Feuil1")
.Range("A11").Value = "Data creazione: " & objFile.DateCreated
.Range("A12").Value = "Data ultimo accesso: " & _
objFile.DateLastAccessed
.Range("A13").Value = "Data ultima modifica: " & _
objFile.DateLastModified
.Range("A14").Value = "Drive: " & objFile.Drive
.Range("A15").Value = "Nome File: " & objFile.Name
.Range("A16").Value = "Cartella - Sottocratella: " & objFile.ParentFolder
.Range("A17").Value = "Path: " & objFile.Path
.Range("A18").Value = "Nome abbreviato: " & objFile.ShortName
.Range("A19").Value = "Path abbreviata: " & objFile.ShortPath
.Range("A20").Value = "Dimensioni: " & objFile.Size
.Range("A21").Value = "Tipo: " & objFile.Type
.Range("A22").Value = "Attr.: " & GetAttr(objFile)
.Range("A23").Value = "Fine percorso: " & finepath
End With
End Sub |
Public Sub RemoveEmptyModules()
'This CANNOT remove Sheet modules
'Can remove Standard modules and Class modules only
'For this to you should have the option "Trust access to the VBA project object model"
'checked. This is under macro security.
Dim objVbComponent As Object
Dim lngStartLine As Long
Dim lngLineCount As Long
Dim lngCntRemove As Long
Const ct_pp_none As Long = 1
Const ct_StdModule As Long = 1
Const ct_ClsModule As Long = 2
For Each objVbComponent In ActiveWorkbook.VBProject.VBComponents
Select Case objVbComponent.Type
Case ct_StdModule, ct_ClsModule
lngStartLine = objVbComponent.CodeModule.CountOfDeclarationLines + 1
lngLineCount = objVbComponent.CodeModule.CountOfLines
If lngLineCount < lngStartLine Then
ActiveWorkbook.VBProject.VBComponents.Remove objVbComponent
lngCntRemove = lngCntRemove + 1
End If
End Select
Next objVbComponent
If lngCntRemove = 0 Then
MsgBox "No empty modules present.", vbInformation, "Excel Experts Tip"
Else
MsgBox lngCntRemove & " empty module(s) removed.", vbInformation, "Excel Experts Tip"
End If
Set objVbComponent = Nothing
End Sub |
QUESTO:
Range("M2").Select
Selection.ClearContents
ActiveCell.FormulaR1C1 = _
"=IF(RC[4]="""",IF(RC[5]="""","""",""*""),IF(RC[1]=R[-1]C[1],""*"",""""))"
Range("M2").Select
Selection.AutoFill Destination:=Range("M2:M55"), Type:=xlFillDefault
Range("M2:M55").Select
SI PUO' RIASSUMERE IN:
Dim x As Long
x = Range("A" & Rows.Count).End(xlUp).Row
Range("M2:M" & x).FormulaR1C1 = "=IF(RC[4]="""",IF(RC[5]="""","""",""*""),IF(RC[1]=R[-1]C[1],""*"",""""))" |
