Domine o Excel ® (3 em 1): Excel - 70 Fórmulas Incríveis, Excel - 51 Macros incríveis e 51 Dicas e Truques Incríveis

(Carla ScalaEjcveS) #1

Workbooks(Filename).Close
Next iCounter
End If
End Sub
Function FindFiles(ByVal sPath As String, ByRef sFoundFiles() As String,
ByRef iArqEncontrados As Integer,

Optional ByVal sFileSpec As String = ".", _
Optional ByVal blIncludeSubFolders As Boolean = False) As Boolean
Dim iCounter As Integer
Dim sFileName As String
Dim oFileSystem As Object, oParentFolder As Object, oFolder As Object
Set oFileSystem = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set oParentFolder = oFileSystem.GetFolder(sPath)
If oParentFolder Is Nothing Then
FindFiles = False
On Error GoTo 0
Set oParentFolder = Nothing
Set oFileSystem = Nothing
Exit Function
End If
sPath = IIf(Right(sPath, 1) = "\", sPath, sPath & "\")
sFileName = Dir(sPath & sFileSpec, vbNormal)
Do While sFileName <> ""
iCounter = UBound(sFoundFiles, 2)
iCounter = iCounter + 1
ReDim Preserve sFoundFiles(1 To 2, 1 To iCounter)
sFoundFiles(1, iCounter) = sPath
sFoundFiles(2, iCounter) = sFileName
sFileName = Dir()
Loop
If blIncludeSubFolders Then
For Each oFolder In oParentFolder.SubFolders
FindFiles oFolder.Path, sFoundFiles, iArqEncontrados, sFileSpec,
blIncludeSubFolders
Next

Free download pdf