Home > database >  How can I select files using the Office FileDIalog from folders where the user does not have permiss
How can I select files using the Office FileDIalog from folders where the user does not have permiss

Time:08-27

I am using the MS Office Appplication.Filedialog in Access VBA for a user to document the location of several files assigned to a project. However, the user dos not have permission to open those documents. He just needs to "pick" them. The dialog cannot select files because the user does not have permission to open the files. Is there a setting in the file dialog that allows files to be just selected, and not infer that they will be opened? If not, is there an alternative file dialog?

CodePudding user response:

I found a solution using the Excel object model.

Using a reference to the Microsoft Excel Object Library the GetOpenFileName method of the Excel Application object displays the file browser dialog and any file can be selected, including those the user does not have permission to open.

Private Function findFiles(filter As String, title As String) As Variant
  
  With New Excel.Application
    findFiles = .GetOpenFileName(fileFilter:=filter, title:=title, MultiSelect:=True)
  End With
  
End Function

From the Microsoft documentation:

The method returns an array with the file names selected, or False, if the user cancelled the dialog.

Application.GetOpenFilename method (Excel) Displays the standard Open dialog box and gets a file name from the user without actually opening any files.

  • Related