#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default TreeView1

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default TreeView1

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




--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)
"vqthomf" wrote in message
...
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default TreeView1

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.

"vqthomf" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default TreeView1

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

"vqthomf" wrote:

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.

"vqthomf" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default TreeView1

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.


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

"vqthomf" wrote in message
...
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

"vqthomf" wrote:

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.

"vqthomf" wrote:

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


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



All times are GMT +1. The time now is 03:26 AM.

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

About Us

"It's about Microsoft Excel"