drop down files in directory list in Word

You would think millions do this...
I am on an intranet. I use Word doc to quickly insert hyperlinks then I use that file to quickly/easily get to and open files.
But how do I use a list box to display files in a directory and then open the file when selected
I know how to work with VBA, the list box etc. But I can't find an example of the code that I need to do this. If I could get any kind of example I could figure it out!!!

Thanks


Answer this question

drop down files in directory list in Word

  • dco


    Well this will get you there:
    Dim MyFile, MyPath, MyName, TEMP


    Private Sub cbxSelect_DropButtonClick()

    MyPath = "c:\"    ' Set the path.
    'MyPath = "\\Svrorlmain\CASS\FA18\TPS_Dvlmp_Support\Templates_Guides_SOIs\TPS_Guides\"
    MyName = Dir(MyPath, vbDirectory)    ' Retrieve the first entry.
    cbxSelect.Clear

    Do While MyName <> ""    ' Start the loop.
        ' Ignore the current directory and the encompassing directory.
        If MyName <> "." And MyName <> ".." Then
            ' Use bitwise comparison to make sure MyName is a directory.
            'TEMP = GetAttr(MyName)
            'Debug.Print (MyPath & MyName)
            If (GetAttr(MyPath & MyName) And vbDirectory) <> vbDirectory Then
                Debug.Print MyName    ' Display entry only if it
                'lbFiles.AddItem ""
                cbxSelect.AddItem (MyName)
                'lbFiles.AddItem MyName
            End If                    ' it represents a file.
        End If
        MyName = Dir    ' Get next entry.
    Loop
    cbxSelect.DropDown
    End Sub



    Private Sub cbxSelect_Click()
        Documents.Open FileName:=MyPath & cbxSelect.Value '
    End Sub




  • drop down files in directory list in Word