excel通过VBA建立多级文件夹

excel 通过VBA建立多级文件夹

用到的excel如图:

Sub newdirs()

Dim strdir As String

Dim rootdir As String

rootdir = InputBox("请输入要建立目录的根目录", "tipinfo", "J:nnn")

If Right(rootdir, 1) <> "" Then rootdir = rootdir + ""

For i = 7 To 284

strdir = rootdir + Sheets(1).Cells(i, 5) + "" + Sheets(1).Cells(i, 3)

Call MDir(strdir)

Next i

MsgBox ("“" & rootdir & "”中各文件夹已建立")

End Sub

'----------------------------------

Sub MDir(ByVal folder As String)

On Error Resume Next

Dim s() As String, i As Long, t As String

s = Split(folder, "")

t = s(0) & "" & s(1)

If dir(t, vbDirectory) = "" Then MkDir t

For i = 2 To UBound(s)

t = t & "" & s(i)

If dir(t, vbDirectory) = "" Then MkDir t

Next

End Sub

以上是 excel通过VBA建立多级文件夹 的全部内容, 来源链接: utcz.com/a/25804.html

回到顶部