Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Path of files

This code put all "excel" files in ListBox1 from folder who start with name
in TextBox1.
Can I change cod that he put all files from any folder(folder and files <
excel file).


Private Sub CommandButton1_Click()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objFolder = objFSO.GetFolder(Me.TextBox1.Text)
On Error GoTo 0
If Not objFolder Is Nothing Then
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then
Me.ListBox1.AddItem objFile.Name
End If
Next
End If
End Sub



Regards
Lopar





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Path of files

Maybe...

Option Explicit
Private Sub CommandButton1_Click()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim objSubFolder As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objFolder = objFSO.GetFolder(Me.TextBox1.Text)
On Error GoTo 0
If Not objFolder Is Nothing Then
For Each objFile In objFolder.Files
'If objFile.Type = "Microsoft Excel Worksheet" Then
Me.ListBox1.AddItem objFile.Name
'End If
Next objFile
For Each objSubFolder In objFolder.subFolders
Me.ListBox1.AddItem objSubFolder.Name
Next objSubFolder
End If
End Sub

If you want to exclude the excel worksheets (I wasn't sure):
change this:

'If objFile.Type = "Microsoft Excel Worksheet" Then
Me.ListBox1.AddItem objFile.Name
'End If
to
If objFile.Type < "Microsoft Excel Worksheet" Then
Me.ListBox1.AddItem objFile.Name
End If

(Uncommented and = changed to <.)



Ivica Lopar wrote:

This code put all "excel" files in ListBox1 from folder who start with name
in TextBox1.
Can I change cod that he put all files from any folder(folder and files <
excel file).

Private Sub CommandButton1_Click()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objFolder = objFSO.GetFolder(Me.TextBox1.Text)
On Error GoTo 0
If Not objFolder Is Nothing Then
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then
Me.ListBox1.AddItem objFile.Name
End If
Next
End If
End Sub

Regards
Lopar


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete/Copy Path Too Long Files Martin Krag Excel Discussion (Misc queries) 0 April 2nd 11 09:40 AM
opening files simultaneously with same name but different path Kim Excel Discussion (Misc queries) 2 September 26th 08 06:18 PM
Show full path of files being saved JERRY Excel Discussion (Misc queries) 4 May 16th 06 07:57 PM
I need to change the path of the linked files - thousands of them. Derekc Excel Discussion (Misc queries) 2 November 21st 05 01:12 PM
Macros i xla-files get incorrect path Roffe Excel Programming 1 April 20th 04 05:04 PM


All times are GMT +1. The time now is 05:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"