Excel planilha vba arquivos mostra as palavras do dicionário de correçao aplicativo

Sáb, 01 de Janeiro de 2011 08:08 Expedito Marcondes
Imprimir

Saberexcel - o site das ma
Essas macros e funções do Aplicativo Microsoft Excel VBA, mostram o dicionário de correção de uma planilha copiando as palavras relacionadas para uma determinada folha de planilha.


Function GetFiles(strPath As String, _
                  dctDict As Scripting.Dictionary, _
                  Optional blnRecursive As Boolean) As Boolean

'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnofftalk/html/office09072000.asp
    
' This procedure returns all the files in a directory into
' a Dictionary object. If called recursively, it also returns
' all files in subfolders.
' La bibliothèque Microsoft Scripting Runtime
' doit être coché dans Outils\Références

    
Dim fsoSysObj      As Scripting.FileSystemObject
Dim fdrFolder      As Scripting.Folder
Dim fdrSubFolder   As Scripting.Folder
Dim filFile        As Scripting.File
    
  ' Return new FileSystemObject.
  Set fsoSysObj = New Scripting.FileSystemObject
    
  On Error Resume Next
  ' Get folder.
  Set fdrFolder = fsoSysObj.GetFolder(strPath)
  If Err <> 0 Then
    ' Incorrect path.
    GetFiles = False
    GoTo GetFiles_End
  End If
  On Error GoTo 0
    
   ' Loop through Files collection, adding to dictionary.
  For Each filFile In fdrFolder.Files
   'récupère nom et chemin complet
    dctDict.Add filFile.Path, filFile.Path
  Next filFile
 
   'If Recursive flag is true, call recursively.
  If blnRecursive Then
    For Each fdrSubFolder In fdrFolder.SubFolders
      GetFiles fdrSubFolder.Path, dctDict, True
    Next fdrSubFolder
  End If
 
   'Return True if no error occurred.
  GetFiles = True
    
GetFiles_End:
     Exit Function
End Function
 
' You can use the following procedure to test the GetFiles procedure.
' This procedure creates a new Dictionary object, passes it to the
' GetFiles procedure, then prints every file in the strDirPath directory
' and every file in any subdirectories to the immediate window.
 
Sub TestGetFiles()
' Call to test GetFiles function.
 
Dim dctDict As Scripting.Dictionary
Dim varItem As Variant
Dim strDirPath As String
    
  strDirPath = "D:\06OfficeVBA\04Modules\"
 
  ' Create new dictionary.
  Set dctDict = New Scripting.Dictionary
  ' Call recursively, return files into Dictionary object.
  If GetFiles(strDirPath, dctDict, True) Then
    Sheets.Add
    'récupère directement le tableau des items du dictionaire
    'dans la colonne A de la nouvelle feuille
    Range("A1:A" & dctDict.Count).Value = _
        Application.Transpose(dctDict.Items)
  End If
End Sub


 

Aprenda tudo sobre o Aplicativo Microsoft Excel VBA, sozinho, praticando com os produtos didáticos SaberExcel

Tags:
Última atualização em Qua, 10 de Agosto de 2011 08:05