List Directory Contents in Menu 
Author Message
 List Directory Contents in Menu

Hi there

What I am trying to do is list directory contents in a menu automatically
and then click on the item (document) selected to insert in a document
rather than using auto text entries.  This is for a precedents system.

Can anyone point me to some code for what I am looking for.

I have the standards for listing a directory into a word document and also
for creating a pop up menu on the fly but can seem to adapt it for what I
need.

Any help appreciated.

Thanks Nick



Fri, 28 Nov 2003 00:20:37 GMT  
 List Directory Contents in Menu
Hi Nick,

Quote:
> What I am trying to do is list directory contents in a menu automatically
> and then click on the item (document) selected to insert in a document
> rather than using auto text entries.  This is for a precedents system.

Does the Insert/File command basically do what you need (just a few steps
further away), or is some functionality you're looking for not covered by
it?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)



Sat, 29 Nov 2003 23:42:32 GMT  
 List Directory Contents in Menu
Hi there

Not really.  I do want to create an insert file.  Rather than do it step by
step I was hoping that the menu could be created on the fly.  What I have so
far is :

My menu name "Precedents"
Then first item is "Start Items".  A click of this and the insert file
command opens at the folder "Start Items".

Further on I have "Clauses". Off this are sub-menus, which are for example
"Restrictive Covenants" and "Service Clauses", again each is click and the
insert file command opens at the folders "Restrictive Covenants" and
"Service Clauses", respectively.

What I was rather hoping was that I could reflect the "Precedents" directory
tree in the menu programmatically ie so it would create on the fly rather
than me having to set it up individually so that if I added another folder
for example "Drainage Clauses" it would then appear in the menu
automatically.  If the contents of the folders could appear even better.  I
have been searching for some code but so far nothing fits.

Hope the above is a bit clearer.

Thanks
Nick



Quote:
> Hi Nick,

> > What I am trying to do is list directory contents in a menu
automatically
> > and then click on the item (document) selected to insert in a document
> > rather than using auto text entries.  This is for a precedents system.

> Does the Insert/File command basically do what you need (just a few steps
> further away), or is some functionality you're looking for not covered by
> it?

> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister
> http://www.mvps.org/word
> http://go.compuserve.com/MSOfficeForum

> This reply is posted in the Newsgroup; please post any follow question or
> reply in the newsgroup and not by e-mail :-)



Sun, 30 Nov 2003 02:14:05 GMT  
 List Directory Contents in Menu
Hi Nick,

Quote:
> What I was rather hoping was that I could reflect the "Precedents" directory
> tree in the menu programmatically ie so it would create on the fly rather
> than me having to set it up individually so that if I added another folder
> for example "Drainage Clauses" it would then appear in the menu
> automatically.  If the contents of the folders could appear even better.  I
> have been searching for some code but so far nothing fits.

It should be possible, I just wanted to be sure that the InsertFile command
was doing the right thing and that you didn't also need to somehow modify this
behavior.

Go into the VBEditor and type CommandBar, then press F1, to get to the Help
for working with toolbars via VBA. And if this is Office 2000, do the same for
FileSystemObject; if it's Word97, look for the Help on the DIR command -
either of these will show how you can loop through folders and sub-folders.
The following Knowledge Base articles should also be of some help.

WD97: How to Add a Drop-down Menu to the Main Menu Bar [Q171130]
WD97: Sample Macro to Create Popup Toolbar [Q185712]
HOWTO: Use FileSystemObject with Visual Basic [Q186118]
WD2000: Sample Macro to List All Files in a Folder [Q236162]
WD97: Macros to List or Print All Documents Found in a Folder [Q180513]

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)



Sun, 30 Nov 2003 21:38:27 GMT  
 List Directory Contents in Menu
Cindy

I have had a look at the articles and what I have done so far is coded
below basically using the code from the articles.

However one thing that is confusing me is the fact that, if you try it
in a folder the first button lists the first file item, the second
button lists both the first item and second item and so on ...

Any further ideas

Sub MenuFolderList()
      Dim cbToolBar As CommandBar
      Dim cbMenuBar As CommandBarPopup
      Dim cbSuBMnu1 As CommandBarButton
      Dim cbSuBMnu2 As CommandBarPopup
      Dim cbSuBMnu2_PopUp As CommandBarButton
      Dim strToolBar As String
      Dim iCount As Integer
      Dim fs, f, f1, fc, s
     ' Replace "My Toolbar" with a name
      ' you want to use for your toolbar.
      strToolBar = "My Toolbar"

      ' If a toolbar of this name already exists,
      ' append a number to the end of name to
      ' differentiate one from the other.
      For Each cbToolBar In CommandBars
         If Left$(cbToolBar.Name, Len(strToolBar)) = strToolBar Then
            iCount = iCount + 1
         End If
      Next

      If iCount > 0 Then strToolBar = strToolBar & iCount

      ' Create and display the Toolbar.
      Set cbToolBar = CommandBars.Add(Name:=strToolBar, _
         Position:=msoBarFloating)
      cbToolBar.Visible = True

      ' Create Main PopUp Menu on Toolbar.
      Set cbMenuBar = cbToolBar.Controls.Add(Type:=msoControlPopup)
      cbMenuBar.Caption = "Main Menu"

      ' Add a Menu Button and a Popup
      ' Menu to the "Main PopUp Menu."
       With cbMenuBar.Controls
         Set cbSuBMnu1 = .Add(Type:=msoControlButton)
         Set cbSuBMnu2 = .Add(Type:=msoControlPopup)
      End With

      ' Set properties for the sub
      ' button and popup menus.
      With cbSuBMnu1
         .Caption = "Sub Menu 1 (Button)"
         .Style = msoButtonCaption
         .OnAction = "ButtonAction1" ' <- Macro to run when clicked.
      End With

      ' Add Popup menu to Sub Menu 2

Set fs = CreateObject("Scripting.FileSystemObject")
' here set your own folder with docs or files in
Set f = fs.GetFolder("E:\Programming\")
    Set fc = f.Files
    For Each f1 In fc
       With cbSuBMnu2
         .Caption = "Sub Menu 2 (Popup)"
      End With
' here is where I get the problem
With cbSuBMnu2.Controls
      Set cbSuBMnu2_PopUp = .Add(Type:=msoControlButton)
      s = s & f1.Name
      cbSuBMnu2_PopUp.Caption = s
      cbSuBMnu2_PopUp.Style = msoButtonCaption
' I have macro for this point in my project
      cbSuBMnu2_PopUp.OnAction = "ButtonAction1" ' <- Macro to run
when clicked.
      End With
      Next

End Sub

Many thanks
Nick


Quote:
> Hi Nick,

> > What I was rather hoping was that I could reflect the "Precedents" directory
> > tree in the menu programmatically ie so it would create on the fly rather
> > than me having to set it up individually so that if I added another folder
> > for example "Drainage Clauses" it would then appear in the menu
> > automatically.  If the contents of the folders could appear even better.  I
> > have been searching for some code but so far nothing fits.

> It should be possible, I just wanted to be sure that the InsertFile command
> was doing the right thing and that you didn't also need to somehow modify this
> behavior.

> Go into the VBEditor and type CommandBar, then press F1, to get to the Help
> for working with toolbars via VBA. And if this is Office 2000, do the same for
> FileSystemObject; if it's Word97, look for the Help on the DIR command -
> either of these will show how you can loop through folders and sub-folders.
> The following Knowledge Base articles should also be of some help.

> WD97: How to Add a Drop-down Menu to the Main Menu Bar [Q171130]
> WD97: Sample Macro to Create Popup Toolbar [Q185712]
> HOWTO: Use FileSystemObject with Visual Basic [Q186118]
> WD2000: Sample Macro to List All Files in a Folder [Q236162]
> WD97: Macros to List or Print All Documents Found in a Folder [Q180513]

> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister
> http://www.mvps.org/word
> http://go.compuserve.com/MSOfficeForum

> This reply is posted in the Newsgroup; please post any follow question or
> reply in the newsgroup and not by e-mail :-)



Mon, 01 Dec 2003 21:42:59 GMT  
 List Directory Contents in Menu
Hi Nick,

Quote:
> However one thing that is confusing me is the fact that, if you try it
> in a folder the first button lists the first file item, the second
> button lists both the first item and second item and so on ...

I think you may "thunk" your head on the desktop or monitor. s & f1.Name
is what's doing it. Just get rid of the first line, below, and use
f1.Name for the .Caption property.

Quote:
> s = s & f1.Name
>       cbSuBMnu2_PopUp.Caption = s

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)



Tue, 02 Dec 2003 02:25:15 GMT  
 List Directory Contents in Menu
Hi there

I did "thunk" my head on the desktop.

Thanks
Nick



Quote:
> Hi Nick,

> > However one thing that is confusing me is the fact that, if you try it
> > in a folder the first button lists the first file item, the second
> > button lists both the first item and second item and so on ...

> I think you may "thunk" your head on the desktop or monitor. s & f1.Name
> is what's doing it. Just get rid of the first line, below, and use
> f1.Name for the .Caption property.

> > s = s & f1.Name
> >       cbSuBMnu2_PopUp.Caption = s

> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister
> http://www.mvps.org/word
> http://go.compuserve.com/MSOfficeForum

> This reply is posted in the Newsgroup; please post any follow question
> or reply in the newsgroup and not by e-mail :-)



Tue, 02 Dec 2003 06:10:46 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Listing Contents of Web Directory

2. Getting directory list of a folder's contents

3. how to list directory contents

4. Listing the contents of a directory through script?

5. List contents of a directory

6. Showing contents of a directory in a list box

7. Listing contents of a directory programmatically

8. list contents of remote directory (http)

9. Getting Start Menu Directory and Favorites Directory Paths by API

10. directories and sub-directories in the list

11. Help: displaying hidden directories in directory list box

12. directories and sub-directories in to a list

 

 
Powered by phpBB® Forum Software