Bonjour,
Voici une proposition de code créant des dossiers, à partir de chaque valeur de la colonne A, dans le dossier téléchargements :
Sub CreerDossiers()
application.screenupdating = false
rep$ = environ("userprofile") & "\Downloads"
with activesheet
dl = .cells(.rows.count, 1).end(xlup).row
for each cell in .columns(1).resize(dl)
hasmade = MakeDir(rep, cell.value)
cell.interior.color = iif(hasmade, vbgreen, vbred)
next cell
end with
application.screenupdating = true
end sub
function MakeDir(spath$, sName$) as boolean
if dir(spath, vbdirectory) = "" then exit function
if dir(spath & "\" & sName, vbdirectory) = "" then
if IsValid(sName) then mkdir spath & "\" & sName: MakeDir = true
end if
end sub
function IsValid(Name$) as boolean
if Name <> "" then
for i = 1 to len(Name)
s = mid(Name, i, 1)
if s like "[<>:""/\[?[*.[[]" then exit function
for j = 1 to 31
if s = chr(j) then exit function
next j
next i
if len(Name) < 260 then IsValid = true
end if
end function
A chaque échec de création, la cellule en question est coloriée en rouge, sinon en vert.
Cdlt,