Excel VBA Folder Picker

Поділитися
Вставка
  • Опубліковано 15 січ 2025

КОМЕНТАРІ • 43

  • @paulbytheriver4976
    @paulbytheriver4976 4 роки тому +1

    Perfect, thanks

  • @AntonisKosmopoulos
    @AntonisKosmopoulos 5 років тому +1

    Thank you, exactly what I was looking for.

  • @David-mu8hn
    @David-mu8hn 5 років тому +1

    Really helpful! Thanks!

  • @Norlen94
    @Norlen94 4 роки тому +1

    Hi Great video. I have a question. Is it possible instead of a predefined directory and range, the user gets to select where the folders would be created and the folders themselves would be based on the cells the user selected? more of a dynamic code.

    • @EverydayVBAExcelTraining
      @EverydayVBAExcelTraining  4 роки тому +1

      Yes you can. It might take a little work to restrict the folders. It is probably easier to set a default directory.

    • @Norlen94
      @Norlen94 4 роки тому +1

      @@EverydayVBAExcelTraining
      Thanks. I created below simple code which works perfectly. It took me a long time though to figure out what to write exactly:
      Sub MakeFolders()
      'Owner: Norlen
      Dim diaFolder As FileDialog
      Dim cell As Range
      Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
      diaFolder.AllowMultiSelect = False
      diaFolder.Show
      fle = diaFolder.SelectedItems(1)
      Set diaFolder = Nothing
      'For Each cell In Application.Selection
      For Each cell In Selection.SpecialCells(xlCellTypeVisible)
      MkDir fle & "\" & cell.Value
      Next cell
      MsgBox "Folders created"
      End Sub

    • @EverydayVBAExcelTraining
      @EverydayVBAExcelTraining  4 роки тому +1

      Well done!

  • @kimrorn9879
    @kimrorn9879 4 роки тому +1

    Hello friends, can you create a video on vba code to get a photo from the folder (Images) located in the workbook location to display in userform?

    • @EverydayVBAExcelTraining
      @EverydayVBAExcelTraining  4 роки тому

      Sorry for the delay. I that would take some work. You would need get all the files links (I think) then loop through them on your from

    • @kimrorn9879
      @kimrorn9879 4 роки тому

      @@EverydayVBAExcelTraining Thank you for all your videos , now I did it.

  • @CAP0NE
    @CAP0NE 4 роки тому +2

    Thank you so much! Quick and clear tutorial. Exactly what I needed! Great job!
    EDIT:
    I get an "Variable not defined" error when running the code.
    Maybe you forgot to declare the variable fle, so code should be:
    ________________________________________
    Sub FolderPicker()
    Dim fle
    Dim diaFolder As FileDialog
    Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
    diaFolder.AllowMultiSelect = False
    diaFolder.Show
    fle = diaFolder.SelectedItems(1)
    Range("C6") = fle
    Set diaFolder = Nothing
    End Sub
    ________________________________________
    One more useful thing. Right now the variable fle is just a String, but if you want to it to manipulate files for example, it must be "converted" to a File Object.
    The below code shows how to set the chosen folder path as an Object for later use:
    ________________________________________
    Sub FolderPicker2()
    Dim fso As New FileSystemObject
    Dim fol As folder
    Dim fil As File
    Dim diaFolder As FileDialog
    Dim fStr As String

    Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
    diaFolder.AllowMultiSelect = False
    diaFolder.Show

    fStr = diaFolder.SelectedItems(1)
    Range("C6") = fStr
    Set fol = fso.getFolder(fStr)
    ' fol is now an FileSystemObject of Type Folder which can be used to manipulate

    ' some code
    ' For Each fil In fol.Files
    ' manipulate files (rename, etc.)
    ' Next
    Set diaFolder = Nothing
    End Sub
    ________________________________________

  • @28851686
    @28851686 6 років тому +1

    Thanks ... It's really helpful

  • @karthikeyanb6897
    @karthikeyanb6897 5 років тому +1

    What is fle..? Since fle is not declared, how you used inside the code. is "fle" predefined variable..?

  • @chennaiam2241
    @chennaiam2241 5 років тому +1

    great solved my problem,, thank you

  • @link_2_learn
    @link_2_learn 5 років тому +1

    Hi is it possible that file or folder selection can be automated in file dialog?

  • @SonLe-wi8ic
    @SonLe-wi8ic 4 роки тому +1

    Thanks.
    But it not work in WPS office or libreoffice. Can you give me an idea?

    • @EverydayVBAExcelTraining
      @EverydayVBAExcelTraining  4 роки тому

      I don't know the code that is used in Libre Office. I have used the code in Google Sheets though

  • @QQ-nb2ic
    @QQ-nb2ic 4 роки тому +1

    Q, how do you open a folder on the computer NOT excel.
    I have a folder I open that contains jpg images and pdf files. How do I get excel to open this folder using vba?

  • @antonyfernando8908
    @antonyfernando8908 5 років тому

    hi friend , can you make a video on vba code to save only the latest open workbook from a master workbook and save it in a path given in a cell reference from the master workbook

  • @radovanraspl240
    @radovanraspl240 6 років тому +1

    Excellent...

  • @radovanraspl240
    @radovanraspl240 6 років тому +1

    When the dialog opens and I click on cancel button, the error appears. How do you handle this error? I did it by "resume next", but I feel this is not the correct way...

  • @naveenprajapati4599
    @naveenprajapati4599 3 роки тому

    In which reference does the application.filedialog belong

  • @linawinny3743
    @linawinny3743 4 роки тому +2

    Avoid getting debug when click button "Cancel" or Close
    If diafolder.Show = -1 Then
    'ok clicked
    fle = diafolder.SelectedItems(1)
    range("C6") = fle
    else
    'Click Cancel
    end if
    set diafolder = nothing

  • @nellaimuthuvels7099
    @nellaimuthuvels7099 2 роки тому

    How to give folder picker in MAC

  • @rahulpandirkar5976
    @rahulpandirkar5976 7 років тому

    what is the use of ..Set diaFolder = Nothing.. ???

    • @EverydayVBAExcelTraining
      @EverydayVBAExcelTraining  7 років тому +1

      +Rahul Pandirkar it is really a best practice.
      It is important to do this when you are connecting to a database because you don't want a hanging connection out there.
      By default these are all dropped once the macro is done running.
      You would also want to do this if you were going to reuse the object.
      Hope this helps

  • @LiquidSnake1988
    @LiquidSnake1988 7 років тому +1

    Or at least tell me what are the functions I need so I can just figure out to put them together. Thanks.

    • @EverydayVBAExcelTraining
      @EverydayVBAExcelTraining  7 років тому

      +LIQUID SNAKE I have never pulled files from one drive. You might need to use the file FSO object but that is just a guess