Saberexcel - o site das macros
Esses procedimentos e declaraçãoes do Aplicativo Microsoft Excel VBA, verificam todos os arquivos que estão na memória do computador, adiciona um folha de planilha no livro ativo e relaciona todos esses arquivos
Private Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, _
ByVal cch As Long) As Long
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Sub criar_lista_arquivos_memoria()
Dim CurrWnd As Long
Dim Length As Long
Dim TaskName As String
Dim Parent As Long
i = 1
Sheets.Add 'cria uma planilha com a relação de arquivos na memoria do computador
twnd& = FindWindow("Shell_traywnd", vbNullString)
CurrWnd = GetWindow(twnd, GW_HWNDFIRST)
While CurrWnd <> 0
Length = GetWindowTextLength(CurrWnd)
TaskName = Space$(Length + 1)
Length = GetWindowText(CurrWnd, TaskName, Length + 1)
TaskName = Left$(TaskName, Len(TaskName) - 1)
If Length > 0 Then
Cells(i, 1).Value = TaskName
i = i + 1
End If
CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
DoEvents
Wend
End Sub
Aprenda tudo sobre o Aplicativo Microsoft Excel VBA, sozinho, praticando com os produtos didáticos SaberExcel
Baixe o exemplo de planilha contendo as macros acima
Excel vba aplicativo relaciona arquivos armazenados memoria (19.88 kB 2010-12-31 12:01:16)