By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,515 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,515 IT Pros & Developers. It's quick & easy.

File Dialog Box Troubleshooting

P: 6
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(msoFileDialogFilePicker)" instead of the actual file path. Any advice? The code I am using is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdFileDialog_Click()
  2. ' This requires a reference to the Microsoft Office 11.0 Object Library.
  3.  
  4.    Dim fDialog As Office.FileDialog
  5.    Dim varFile As Variant
  6.  
  7.    ' Set up the File dialog box.
  8.    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
  9.    With fDialog
  10.       ' Allow the user to make multiple selections in the dialog box.
  11.       .AllowMultiSelect = False
  12.  
  13.       ' Clear out the current filters, and then add your own.
  14.       .Filters.Clear
  15.       .Filters.Add "All Files", "*.*"
  16.  
  17.       ' Show the dialog box. If the .Show method returns True, the
  18.       ' user picked at least one file. If the .Show method returns
  19.       ' False, the user clicked Cancel.
  20.       If .Show = True Then
  21.          Me.FileLink = .Item
  22.               Else
  23.          MsgBox "You clicked Cancel in the file dialog box."
  24.       End If
  25.    End With
  26.  
  27. End Sub
Apr 19 '07 #1
Share this Question
Share on Google+
1 Reply


SammyB
Expert 100+
P: 807
It should be .SelectedItems(1)
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Private Sub cmdFileDialog_Click()
  3.     ' This requires a reference to the Microsoft Office 11.0 Object Library.
  4.  
  5.     Dim fDialog As Office.FileDialog
  6.     Dim varFile As Variant
  7.  
  8.     ' Set up the File dialog box.
  9.     Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
  10.     With fDialog
  11.         ' Allow the user to make multiple selections in the dialog box.
  12.         .AllowMultiSelect = False
  13.  
  14.         ' Clear out the current filters, and then add your own.
  15.         .Filters.Clear
  16.         .Filters.Add "All Files", "*.*"
  17.  
  18.         ' Show the dialog box. If the .Show method returns True, the
  19.         ' user picked at least one file. If the .Show method returns
  20.         ' False, the user clicked Cancel.
  21.         If .Show = True Then
  22.             MsgBox .SelectedItems(1)
  23.         Else
  24.             MsgBox "You clicked Cancel in the file dialog box."
  25.         End If
  26.     End With
  27.  
  28. End Sub
Apr 19 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.