Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Oklahoma, Oklahoma, USA
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File List box on Word toolbar (Word 2000 Professional)

    Word is married into a document management system here so we don't have access to Word's native Open File dialog box; I have a user that wants a box on her toolbar that lets her click and get a drop down list of files in a certain directory on her hard drive; what code would I use to be able to accomplish that?

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: File List box on Word toolbar (Word 2000 Professional)

    If you can't use Word's functionality, you can always fall back on the WinAPI. Here's a link to an article from The Access Web that should be adaptable to Word VBA. You can also get a library pre-written to handle this from http://ourworld.compuserve.com/homepages/a...-cg/acgsoft.htm for a small fee.
    Charlotte

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: File List box on Word toolbar (Word 2000 Professional)

    You could start up the native Word File Open function at a specified path, but it would be difficult to prevent the user from navigating to the server. Charlotte's method probably would resolve that issue because the WinAPI lets you specify the "root" from which browsing takes place. Alternately, if this is not a big folder, you could literally read all of the file names from a specified folder into a drop-down control. (After I log off, I'm going to see if I am even somewhat right in that claim!)

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: File List box on Word toolbar (Word 2000 Professional)

    I built and ran this from an unsaved document; YMMV. It uses the old-fashioned Dir command; FileSystemObject or FileSearch object would be fancier and might have additional desirable features. I can't say that I fully understand the CommandBar object and controls...the .Style property and .AddItem method are not suggested in the auto-whatever-they're-called prompts, which suggests that I did not property define the control type in the first place. On the other hand, the code runs!!

    The first procedure is a one-time to create a custom toolbar. The one button is wired to the second procedure. The second procedure populates the drop down with file names. It will delete any old drop-downs or other controls before adding the new drop-down. The third procedure is the action for the drop-down control itself.

    <pre>Sub SetupCBar()
    'Next line for testing only
    CustomizationContext = ThisDocument
    Dim cbarNew As CommandBar
    Set cbarNew = CommandBars.Add("DropBarTest", msoBarTop, , False)
    cbarNew.Visible = True
    Dim cbCtrl As CommandBarControl
    Set cbCtrl = cbarNew.Controls.Add(msoControlButton)
    With cbCtrl
    .Caption = "Show List"
    .Style = msoButtonCaption
    .OnAction = "Populate"
    End With
    Set cbCtrl = Nothing
    Set cbarNew = Nothing
    End Sub

    Sub Populate()
    If Dir("C:Testing*.doc") = vbNullString Then
    MsgBox "No files to list in c:testing"
    Exit Sub
    End If
    Dim cbarDrop As CommandBar
    Set cbarDrop = CommandBars("DropBarTest")
    Do While cbarDrop.Controls.Count > 1
    cbarDrop.Controls(cbarDrop.Controls.Count).Delete
    Loop
    Dim cbCtrl As CommandBarControl
    Set cbCtrl = cbarDrop.Controls.Add(msoControlDropdown, , , , True)
    Dim strFileName
    strFileName = Dir("c:testing*.doc")
    Do
    If strFileName = vbNullString Then Exit Do
    cbCtrl.AddItem strFileName
    strFileName = Dir
    Loop
    With cbCtrl
    .OnAction = "OpenDaFile"
    .Width = 300
    End With
    Set cbCtrl = Nothing
    Set cbarDrop = Nothing
    End Sub

    Sub OpenDaFile()
    Documents.Open "c:testing" & CommandBars("DropBarTest").Controls(2).Text
    End Sub</pre>

    Hope this helps. Until they want to save outside of WDX, and then...

  5. #5
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Oklahoma, Oklahoma, USA
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File List box on Word toolbar (Word 2000 Professional)

    Thanks for the responses on this. What I actually have in this situation is firm templates that are downloaded to the local drive and then they show up under Named Tabs under File|New - simple enough. However, I have one user (a prominent somebody) that does not want to have to click different tabs to access different things so she wants her templates to show up under the General Tab instead of a Tab with her name on it. This could be a simple Copy and Paste but she does not want to be bogged down with that so one of our IT guys tried to write code to do it. For some reason the code that was written by our guy doesn't work and copy the files from her named tab to the general tab - the code just doesn't copy the files - and the code is in a .bat file which I don't know how to write or edit. Anyway, I thought if I could get her personal templates to display in a drop down box from her toolbar that would resolve it and she wouldn't have to click different tabs (even though Word defaults back to the last tab you accessed, she has another tab that she uses from so she doesn't want to have to waste time clicking around between them). So, basically I'm trying to accomplish point and click access to her templates with minimal actions. I could hard code a drop down list with macros to go fire the templates from their place but that would require me to re-edit the code everytime she made a new template. Sheeesh! Pleasing important people can be very challenging.

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: File List box on Word toolbar (Word 2000 Professional)

    That scenario requires some serious design changes to my code, since I was focusing on only one folder at a time. However, the batch file should be easy as long as it can find the right paths. Sometimes long folder names can create complications. VBScript can be substituted for DOS commands for this sort of thing. Try to turn on your IT people to the FileSystemObject. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •