Group:  Microsoft Word ยป microsoft.public.word.vba.userforms
Thread: userform won't show & can't list sub folder names

Geek News

userform won't show & can't list sub folder names
John Schultz 5/27/2007 11:06:50 PM
I can't get my userform to show. I tried "NameOfForm.Show", but it does not recognize the object. What am I missing?

I am trying to create a drop-down in a userform that lists all the subfolders in a particular folder that I specify. Is there a collection for subfolders? Where do I access a list of subfolders?

Thanks,
John


EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Re: userform won't show & can't list sub folder names
"Jean-Guy Marcil" <DontEvenTry[ at ]NoSpam> 5/28/2007 4:26:09 AM
John Schultz was telling us:
John Schultz nous racontait que :

[Quoted Text]
> I can't get my userform to show. I tried "NameOfForm.Show", but it
> does not recognize the object. What am I missing?

Show us the full Sub you are using to call the userform.
Do you have any code in the initialize or Activate events of the userform?

> I am trying to create a drop-down in a userform that lists all the
> subfolders in a particular folder that I specify. Is there a
> collection for subfolders? Where do I access a list of subfolders?

Do you have any code for this yet?

In any case, here is an example of one of the many ways you could do this.
This example assumes that you have a userform named "frmSubFolders" which
contains a combobox named "cmbSubFolder" and a command button that only has
the following code:
Me.Hide


'_______________________________________
Option Explicit
'_______________________________________
Sub Main()

Dim frmMain As frmSubFolders
Dim colList As Collection
Dim i As Long

Set colList = colSubFolder
Set frmMain = New frmSubFolders

With frmMain
For i = 1 To colList.Count
.cmbSubFolder.AddItem colList(i)
Next
.Show
End With

Unload frmMain

Set frmMain = Nothing

End Sub
'_______________________________________

'_______________________________________
Function colSubFolder() As Collection

Dim strPath As String
Dim strSubFolder As String

Set colSubFolder = New Collection

strPath = "C:\Clients\"

strSubFolder = Dir(strPath, vbDirectory)
Do While strSubFolder <> ""
'Ignore the current folder and parent folder
If strSubFolder <> "." And strSubFolder <> ".." Then
'Make sure strSubFolder is a folder.
If (GetAttr(strPath & strSubFolder) And vbDirectory) _
= vbDirectory Then
'Add to collection
colSubFolder.Add strSubFolder
End If
End If
'Get next folder
strSubFolder = Dir
Loop

End Function
'_______________________________________

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE[ at ]CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org


Re: userform won't show & can't list sub folder names
"Jonathan West" <jwest[ at ]mvps.org> 5/28/2007 2:31:17 PM

<John Schultz> wrote in message news:200752719650john_a_schultz[ at ]yahoo.com...
[Quoted Text]
>I can't get my userform to show. I tried "NameOfForm.Show", but it does
>not recognize the object. What am I missing?
>
> I am trying to create a drop-down in a userform that lists all the
> subfolders in a particular folder that I specify. Is there a collection
> for subfolders? Where do I access a list of subfolders?
>

You might like to try using the CCRP FolderTreeView control. Although
written for VB6, it should work perfectly happily in a VBA userform. Take a
look here. It's free!

http://ccrp.mvps.org/index.html?controls/ccrpftv6.htm


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net