Create folders based on cell values in Excel + create hyperlink
Sub MakeFolders()
Dim Rng As Range
Dim maxRows, maxCols, r, c As Integer
Set Rng = Selection
maxRows = Rng.Rows.Count
maxCols = Rng.Columns.Count
For c = 1 To maxCols
r = 1
Do While r <= maxRows
If Len(Dir(ActiveWorkbook.Path & "\" & Rng(r, c), vbDirectory)) = 0 Then
MkDir (ActiveWorkbook.Path & "\" & Rng(r, c))
On Error Resume Next
End If
r = r + 1
Loop
Next c
End Sub
This VBA is to create folders, but you have to select the cells that contain the folder names before running this code
Also you cannot write /
and \
in Windows you can use \
for folders but not names of folders
Reserved Characters and Names
Most common characters can be used in naming files. However, the following characters are reserved and cannot be used in a file name:
< > : " / \ | ? *
Also, neither a space nor a period can be used at the end of a name. Further, files cannot have the following reserved device names: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Note that the case does not matter in Windows.
It is explained on this link.
Related videos on Youtube
Luc
Updated on September 18, 2022Comments
-
Luc almost 2 years
I have the following cell values (Column
FOLDERNAME
) for which I'd like to automatically create a folder in my current spreadsheet active directory.How to do that, this is my first question?
Inside each folder I'd like the next value (Column
DRAWING_FILE
) to be displayed as a hyperlink.How to do that, this is my second question?
-
Prasanna over 8 yearsWhich Operating system are you on? Windows? Mac? What Excel version are you using?
-
Aganju over 8 yearsWhat did you try already?
-
Luc over 8 yearsI'm on Win 7 Pro, using MS Excel 2010
-
-
Burgi over 8 yearsI've attempted to fix your formatting. Could you possibly explain why the OP can't use \ or
_
characters? -
Luc over 8 yearsThe VBA works for creating folders but it seems that \ can't be use either. Any luck at creating the hyperlink within each folders?
-
Roberto Barile over 8 years@Burgi it is explained in this link vlaurie.com/computers2/Articles/filenames.htm
-
Roberto Barile over 8 years@Luc \ correspond to a parent folder you should create it first or modify the VBA code to create it before the other folders