File Dialog Box Troubleshooting

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mvlt
    New Member
    • Apr 2007
    • 6

    File Dialog Box Troubleshooting

    I am trying to create a button and related text box that allows a user to click, open the standard Windows File Dialog Box and populate the text box with the selected file path, which will then be a hyperlink.

    I can get the button to open the File Dialog Box, but when I close it returns "FileDialog(mso FileDialogFileP icker)" instead of the actual file path. Any advice? The code I am using is:

    Code:
    Private Sub cmdFileDialog_Click()
    ' This requires a reference to the Microsoft Office 11.0 Object Library.
    
       Dim fDialog As Office.FileDialog
       Dim varFile As Variant
    
       ' Set up the File dialog box.
       Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
       With fDialog
          ' Allow the user to make multiple selections in the dialog box.
          .AllowMultiSelect = False
                
          ' Clear out the current filters, and then add your own.
          .Filters.Clear
          .Filters.Add "All Files", "*.*"
    
          ' Show the dialog box. If the .Show method returns True, the
          ' user picked at least one file. If the .Show method returns
          ' False, the user clicked Cancel.
          If .Show = True Then
             Me.FileLink = .Item
                  Else
             MsgBox "You clicked Cancel in the file dialog box."
          End If
       End With
    
    End Sub
    Last edited by Killer42; Apr 20 '07, 03:02 AM. Reason: Please use [CODE]...[/CODE] tags around your code.
  • SammyB
    Recognized Expert Contributor
    • Mar 2007
    • 807

    #2
    It should be .SelectedItems( 1)
    Code:
    Option Explicit
    Private Sub cmdFileDialog_Click()
    	' This requires a reference to the Microsoft Office 11.0 Object Library.
     
    	Dim fDialog As Office.FileDialog
    	Dim varFile As Variant
     
    	' Set up the File dialog box.
    	Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    	With fDialog
    		' Allow the user to make multiple selections in the dialog box.
    		.AllowMultiSelect = False
     
    		' Clear out the current filters, and then add your own.
    		.Filters.Clear
    		.Filters.Add "All Files", "*.*"
     
    		' Show the dialog box. If the .Show method returns True, the
    		' user picked at least one file. If the .Show method returns
    		' False, the user clicked Cancel.
    		If .Show = True Then
    			MsgBox .SelectedItems(1)
    		Else
    			MsgBox "You clicked Cancel in the file dialog box."
    		End If
    	End With
     
    End Sub

    Comment

    Working...