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 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
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 ________________________________________
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?
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
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...
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
+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
Perfect, thanks
You're welcome!
Thank you, exactly what I was looking for.
Glad it helped
Really helpful! Thanks!
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.
Yes you can. It might take a little work to restrict the folders. It is probably easier to set a default directory.
@@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
Well done!
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?
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
@@EverydayVBAExcelTraining Thank you for all your videos , now I did it.
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
________________________________________
Great comment and awesome code!
Thanks ... It's really helpful
Thanks for the feedback
What is fle..? Since fle is not declared, how you used inside the code. is "fle" predefined variable..?
Fle is an undefined variable
@@EverydayVBAExcelTrainingthanks..!! And your videos are awesome..!!
great solved my problem,, thank you
Hi is it possible that file or folder selection can be automated in file dialog?
Do you mean set the default. Yes that can be done
Thanks.
But it not work in WPS office or libreoffice. Can you give me an idea?
I don't know the code that is used in Libre Office. I have used the code in Google Sheets though
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?
That is a tough one to do in Excel. I would look into Knime
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
Excellent...
Thanks for the props
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...
That works. I would do an on error go-to and check the error number
In which reference does the application.filedialog belong
I am not sure I am following?
Filedialog is the window that opens for files
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
How to give folder picker in MAC
To be honest I don't know. Have you checked stack overflow
@@EverydayVBAExcelTraining not able to find..
what is the use of ..Set diaFolder = Nothing.. ???
+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
Or at least tell me what are the functions I need so I can just figure out to put them together. Thanks.
+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