2

I'm using FileDialog with the msoFileDialogFolderPicker option and what I want to do is to allow the user to browse for a zip file or a folder.

Is there any way to include zip files in this dialog and check if the clicked file is a .zip file or a folder in Excel VBA?

This code only gets a folder:

Sub browseFolder()

    Dim diaFolder As FileDialog

    ' Open the file dialog
    Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
    diaFolder.AllowMultiSelect = False
    diaFolder.Show

    Sheet1.filePath.Value = diaFolder.SelectedItems(1)

End Sub
Robin Mackenzie
  • 18,801
  • 7
  • 38
  • 56
Eem Jee
  • 1,239
  • 5
  • 30
  • 64
  • have a look here - https://msdn.microsoft.com/en-us/library/office/ff836226.aspx . For what I recall off the top of my head the file picker wont let you select a folder as it will always go into it and display the contents so if you use Application.FileDialog(msoFileDialogFilePicker) it should always be a file.. – Captain Grumpy Dec 05 '16 at 10:23
  • @CaptainGrumpy Yeah I'm aware of it. But is there anyway that a user can select a folder or a zipped file using one browse button only? – Eem Jee Dec 05 '16 at 10:33
  • From everything I have seen, not easily. There appears to be a few workarounds available. https://www.codeproject.com/kb/dialog/openfileorfolderdialog.aspx it might be easier to make a userform and ask the user if they want a file or folder then use the respective picker. Or you could do a folder select and then display all valid files in that folder in a userform and let them select from there, – Captain Grumpy Dec 05 '16 at 18:15
  • @CaptainGrumpy But the site only provides C# workarounds. It's not an excel VBA. Thanks. – Eem Jee Dec 06 '16 at 02:32
  • Look at @Comintern answer - http://stackoverflow.com/a/29761436/4539709 – 0m3r Feb 20 '17 at 04:50

0 Answers0