Private Sub Create_Folder()
Dim strDateiname As String
strFolderPath01 = "C:\Users\" & Environ("Username") & "\Documents\Beispiel01\" & Format(Now, "yyyy") & "\Beispiel02\"
strFolderPath02 = "C:\Users\" & Environ("Username") & "\Documents\Beispiel01\" & Format(Now, "yyyy") & "\Beispiel02\" & Format(Now, "mm") & " " & Format(Now, "mmmm") & " " & Format(Now, "yyyy") & "\"
strFolderPath03 = "C:\Users\" & Environ("Username") & "\Documents\Beispiel01\" & Format(Now, "yyyy") & "\Beispiel02\" & Format(Now, "mm") & " " & Format(Now, "mmmm") & " " & Format(Now, "yyyy") & "\" & Format(Now, "dd.mm") & " " & "Lokal" & "\"
strFolderPath04 = "C:\Users\" & Environ("Username") & "\Documents\Beispiel01\" & Format(Now, "yyyy") & "\Beispiel02\" & Format(Now, "mm") & " " & Format(Now, "mmmm") & " " & Format(Now, "yyyy") & "\" & Format(Now, "dd.mm") & " " & "Lokal" & "\" & Range("F173").Text & "\"
strFolderPath05 = "C:\Users\" & Environ("Username") & "\Documents\Beispiel01\" & Format(Now, "yyyy") & "\Beispiel02\" & Format(Now, "mm") & " " & Format(Now, "mmmm") & " " & Format(Now, "yyyy") & "\" & Format(Now, "dd.mm") & " " & "Lokal" & "\" & Range("F173").Text & "\" & "Beispiel03"
strFolderPath06 = "C:\Users\" & Environ("Username") & "\Documents\Beispiel01\" & Format(Now, "yyyy") & "\Beispiel02\" & Format(Now, "mm") & " " & Format(Now, "mmmm") & " " & Format(Now, "yyyy") & "\" & Format(Now, "dd.mm") & " " & "Lokal" & "\" & Range("F173").Text & "\" & "Beispiel04"
If Dir(strFolderPath01, vbDirectory) = "" Then
' Ordner anlegen
MkDir (strFolderPath01)
Else
' mache irgendwas
End If
If Dir(strFolderPath02, vbDirectory) = "" Then
' Ordner anlegen
MkDir (strFolderPath02)
Else
' mache irgendwas
End If
If Dir(strFolderPath03, vbDirectory) = "" Then
' Ordner anlegen
MkDir (strFolderPath03)
Else
' mache irgendwas
End If
If Dir(strFolderPath04, vbDirectory) = "" Then
' Ordner anlegen
MkDir (strFolderPath04)
Else
' mache irgendwas
End If
If Dir(strFolderPath05, vbDirectory) = "" Then
' Ordner anlegen
MkDir (strFolderPath05)
Else
' mache irgendwas
End If
If Dir(strFolderPath06, vbDirectory) = "" Then
' Ordner anlegen
MkDir (strFolderPath06)
Else
' mache irgendwas
End If
'Ordner öffnen
Call Shell("explorer.exe" & " " & strFolderPath03, vbNormalFocus)
End Sub
Private Declare PtrSafe Function MakeSureDirectoryPathExists Lib "imagehlp.dll" ( _
ByVal DirPath As String) As Long
sub New_Filder()
dim rtn as long
rtn = MakeSureDirectoryPathExists("c:\temp\Ordner_neu")
end sub
Option Explicit
#If VBA7 Then
Declare PtrSafe Function MakePath Lib "imagehlp.dll" Alias "MakeSureDirectoryPathExists" (ByVal lpPath As String) As Long
#Else
Declare Function MakePath Lib "imagehlp.dll" Alias "MakeSureDirectoryPathExists" (ByVal lpPath As String) As Long
#End If
Sub APIMakeSureDirectoryPathExists(strVerzeichnis As String)
If MakePath(strVerzeichnis) = 0 Then
MsgBox "Verzeichnis konnte nicht erstellt werden!", vbCritical
End
End If
End Sub
Sub LegVerzeichnisAn()
Dim i&, arrPfade(), Pfad$
arrPfade = Array("C:\Users\" & Environ("Username") & "\Documents\Beispiel01\" & Format(Now, "yyyy") & "\Beispiel02", _
"C:\Users\" & Environ("Username") & "\Documents\Beispiel01\" & Format(Now, "yyyy") & "\Beispiel02\" & Format(Now, "mm") & " " & Format(Now, "mmmm") & " " & Format(Now, "yyyy") & "\", _
"C:\Users\" & Environ("Username") & "\Documents\Beispiel01\" & Format(Now, "yyyy") & "\Beispiel02\" & Format(Now, "mm") & " " & Format(Now, "mmmm") & " " & Format(Now, "yyyy") & "\" & Format(Now, "dd.mm") & " " & "Lokal" & "\", _
"C:\Users\" & Environ("Username") & "\Documents\Beispiel01\" & Format(Now, "yyyy") & "\Beispiel02\" & Format(Now, "mm") & " " & Format(Now, "mmmm") & " " & Format(Now, "yyyy") & "\" & Format(Now, "dd.mm") & " " & "Lokal" & "\" & Range("F173").Text & "\", _
"C:\Users\" & Environ("Username") & "\Documents\Beispiel01\" & Format(Now, "yyyy") & "\Beispiel02\" & Format(Now, "mm") & " " & Format(Now, "mmmm") & " " & Format(Now, "yyyy") & "\" & Format(Now, "dd.mm") & " " & "Lokal" & "\" & Range("F173").Text & "\" & "Beispiel03", _
"C:\Users\" & Environ("Username") & "\Documents\Beispiel01\" & Format(Now, "yyyy") & "\Beispiel02\" & Format(Now, "mm") & " " & Format(Now, "mmmm") & " " & Format(Now, "yyyy") & "\" & Format(Now, "dd.mm") & " " & "Lokal" & "\" & Range("F173").Text & "\" & "Beispiel04")
For i = 0 To UBound(arrPfade)
Pfad = arrPfade(i)
Call APIMakeSureDirectoryPathExists(Pfad)
Next i
End Sub
arrPfade = Array("C:\Users\" & Environ("Username") & "\Documents\Beispiel01\" & Format(Now, "yyyy") & "\Beispiel02\" & Format(Now, "mm") & " " & Format(Now, "mmmm") & " " & Format(Now, "yyyy") & "\" & Format(Now, "dd.mm") & " " & "Lokal" & "\" & Range("F173").Text & "\" & "Beispiel03", _
"C:\Users\" & Environ("Username") & "\Documents\Beispiel01\" & Format(Now, "yyyy") & "\Beispiel02\" & Format(Now, "mm") & " " & Format(Now, "mmmm") & " " & Format(Now, "yyyy") & "\" & Format(Now, "dd.mm") & " " & "Lokal" & "\" & Range("F173").Text & "\" & "Beispiel04")
Private Sub Create_Folder()
Dim strDateiname As String
Dim strFolderPath01 As String
Dim strFolderPath02 As String
Dim strFolderPath03 As String
Dim strFolderPath04 As String
Dim strFolderPath05 As String
Dim strFolderPath06 As String
Dim pfad_array As Variant
Teil_A As String
Teil_B As String
Teil_D As String
Teil_D As String
Teil_A = "C:\Users\" & Environ("Username") & "\Documents\Beispiel01\" & Format(Now, "yyyy") & "\Beispiel02\"
Teil_B = Format(Now, "mm") & " " & Format(Now, "mmmm") & " " & Format(Now, "yyyy") & "\"
Teil_C = Format(Now, "dd.mm") & " " & "Lokal" & "\"
strFolderPath01 = Teil_A
strFolderPath02 = Teil_A & Teil_B
strFolderPath03 = Teil_A & Teil_B & Teil_C
For Each cl In Range("B1:B200").SpecialCells(xlConstants)
Teil_D = Range("F" & cl.Row).Text
strFolderPath04 = strFolderPath03 & Teil_D & "\"
strFolderPath05 = strFolderPath03 & Teil_D & "\" & "Beispiel03"
strFolderPath06 = strFolderPath03 & Teil_D & "\" & "Beispiel04"
pfad_array = Array(strFolderPath01, strFolderPath02, strFolderPath03, strFolderPath04, strFolderPath05, strFolderPath06)
For I = 0 To UBound(pfad_array)
If Dir(pfad_array(I), vbDirectory) = "" Then
' Ordner anlegen
MkDir (pfad_array(I))
Else
' mache irgendwas
End If
Next I
Next cl
'Ordner öffnen
Call Shell("explorer.exe" & " " & strFolderPath03, vbNormalFocus)
End Sub
Dim strDateiname As String
Dim pa, j, m1, m2, txt
pa = "C:\Users\" & Environ("Username") & "\Documents\Beispiel01\"
j = Format(Now, "yyyy")
m1 = Format(Now, "mm")
m2 = Format(Now, "mmmm")
dm = Format(Now, "dd.mm")
txt = Range("F173").Text
strFolderPath01 = pa & j & "\Beispiel02\"
strFolderPath02 = strFolderPath01 & m1 & " " & m2 & " " & j & "\"
strFolderPath03 = strFolderPath02 & dm & " " & "Lokal" & "\"
strFolderPath04 = strFolderPath03 & txt & "\"
strFolderPath05 = strFolderPath04 & "Beispiel03"
strFolderPath06 = strFolderPath04 & "Beispiel04"
If Dir(strFolderPath01, vbDirectory) = "" Then
....
....
dim rngB as range
for each rngB in Sheet("MG Werte").Range("B:B").SpecialCells(xlcelltypeconstants, 2)
'rngB.Value ist dann die Variable mit dem jeweiligen Text
next
Sub OrdnerErstellen()
Dim p As Long
Dim OrdnerPfad As String
OrdnerPfad = "C:\Users\xxxxx\Downloads\Test1\Test2\" 'anzulegende Ordnerstrkutur mit "\" am Ende
p = 0
Do
p = InStr(p + 1, OrdnerPfad, "\")
If p = 0 Then Exit Do
If Dir(Left(OrdnerPfad, p - 1), vbDirectory) = "" Then MkDir Left(OrdnerPfad, p - 1)
Loop
End Sub