Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2007

Tip: Looking for answers? Try searching our database.

TreeView1

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vqthomf - 14 Sep 2007 09:50 GMT
Hi I have been trying to load folder and sub folders and file, I can first
level folders but having problem trying to get second etc.
If anybody could it would be much appreciated.
Charles
Chip Pearson - 14 Sep 2007 10:47 GMT
Try code like the following in the userform that contains the TreeView:

Private Sub CommandButton1_Click()
   Dim TopFolderStr As String
   Dim TopFolder As Scripting.Folder
   Dim FSO As Scripting.FileSystemObject
   Dim TopNode As Node

   TopFolderStr = "C:\TopLevelFolder"
   Set FSO = New Scripting.FileSystemObject
   Set TopFolder = FSO.GetFolder(TopFolderStr)

   Set TopNode = UserForm1.TreeView1.Nodes.Add(Text:=TopFolder.Name)
   DoFolder FSO, UserForm1.TreeView1, TopFolder, TopNode
End Sub

Private Sub DoFolder(FSO As Scripting.FileSystemObject, _
   TVX As TreeView, WhatFolder As Scripting.Folder, _
   WhatFolderNode As Node)

   Dim FF As Scripting.Folder
   Dim F As Scripting.File
   Dim FFNode As Node
   Dim FNode As Node
   Dim SubFF As Scripting.Folder

   For Each FF In WhatFolder.SubFolders
       Set FFNode = TVX.Nodes.Add(WhatFolderNode, tvwChild, , FF.Name)
       For Each F In FF.Files
           Set FNode = TVX.Nodes.Add(FFNode, tvwChild, , F.Name)
       Next F
       For Each SubFF In WhatFolder.SubFolders
           DoFolder FSO, TVX, FF, FFNode
       Next SubFF
   Next FF
End Sub

Signature

Cordially,
Chip Pearson
Microsoft MVP  - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)

> Hi I have been trying to load folder and sub folders and file, I can first
> level folders but having problem trying to get second etc.
> If anybody could it would be much appreciated.
> Charles
vqthomf - 14 Sep 2007 11:22 GMT
Thanks Chip I do have one question when I run the code I get duplicate
Folders [6 times] I have stepped through the code but can't see where it's
doing it?
Regards
Charles
PS I like the code I was using different function to try and do the same
thing.

> Hi I have been trying to load folder and sub folders and file, I can first
> level folders but having problem trying to get second etc.
> If anybody could it would be much appreciated.
> Charles
vqthomf - 14 Sep 2007 13:18 GMT
Thamks Chip I have work out what was caused the Dups I removed For Each SubFF
In WhatFolder.SubFolders and it was okay
Regards
Charles

> Thanks Chip I do have one question when I run the code I get duplicate
> Folders [6 times] I have stepped through the code but can't see where it's
[quoted text clipped - 8 lines]
> > If anybody could it would be much appreciated.
> > Charles
Chip Pearson - 14 Sep 2007 14:26 GMT
> Thamks Chip I have work out what was caused the Dups I removed For Each
> SubFF
> In WhatFolder.SubFolders and it was okay

You need that code if you are looping through an arbitrary level of nest
folders and files.

Signature

Cordially,
Chip Pearson
Microsoft MVP  - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)

> Thamks Chip I have work out what was caused the Dups I removed For Each
> SubFF
[quoted text clipped - 16 lines]
>> > If anybody could it would be much appreciated.
>> > Charles
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.