Notifications
Clear all

Lista de Arquivos num ListBox

4 Posts
1 Usuários
0 Reactions
1,547 Visualizações
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Olá!

O código abaixo pode ser adaptado para listar os arquivos numa ListBox de um formulário Excel ao invés de exibir uma mensagem com a lista?

Sub ShowFileList()

Dim fs, f, f1, fc, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder("C:Temp")
Set fc = f.Files
For Each f1 In fc
s = s & f1.Name & ":"
s = s & vbCrLf
s = s & f1.Size & " bytes"
s = s & vbCrLf
Next
MsgBox s

End Sub

Aguardo.

Grato. :ugeek:

 
Postado : 29/10/2010 1:09 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Você quer listas arquivos de um diretório dentro do form blz?

 
Postado : 29/10/2010 1:48 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Olá Caio!

é isso mesmo.
Já tinha uma macro que rodava no Excel 2003, mas agora como foi atualizado para o 2010 ela não funciona e estou tentando começar uma nova macro do zero.

Grato.

 
Postado : 29/10/2010 2:58 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Cara, esse código aqui lista itens de um diretórios para um listbox em um form vba

Ve se ajuda

Dim fileList() As String
Dim fName As String
Dim fPath As String
Dim I As Integer
'define the directory to be searched for files
fPath = "C:"

'build a list of the files
fName = Dir(fPath & "*")
While fName <> ""
'add fName to the list
I = I + 1
ReDim Preserve fileList(1 To I)
fileList(I) = fName
'get next filename
fName = Dir()
Wend
'see if any files were found
If I = 0 Then
MsgBox "No files found"
Exit Sub
End If
'cycle through the list and add to listbox
For I = 1 To UBound(fileList)
Me.ListBox1.AddItem fileList(I)
Next

 
Postado : 04/11/2010 5:37 pm