vba在当前目录下建立新的文件夹

我现在想在excel同级的目录下建立一个文件夹,不知道路径该如何表示,用相对路径,谢谢!

试试下面的代码:在当前目录下依次创建指定文件夹

Sub test()
    Dim arr, arrTemp
    Dim strPath As String
    Dim strTemp
    Dim i As Long, j As Long
    On Error Resume Next
    strPath = ThisWorkbook.Path & Application.PathSeparator
    arr = Sheet1.Range("a1").CurrentRegion
    For i = LBound(arr) + 1 To UBound(arr)
        strTemp = strPath
        arrTemp = Split(arr(i, 1), "")
        For j = LBound(arrTemp) To UBound(arrTemp)
            strTemp = strTemp & arrTemp(j) & Application.PathSeparator
            MkDir strTemp
        Next
    Next
End Sub

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-03-29

excel获取当前工作簿路径

ThisWorkbook.Path

excel新建文件夹

MkDir "c:\temp"

第2个回答  2018-03-29
是可以的。请用以下代码进行测试:

hMkDir ("D:\1\2\3\4\") ‘调用测试
’===================

Sub hMkDir(fPath As String)
Dim sp() As String, k%, strP$
If fPath = "" Then Exit Sub
strP$ = IIf(Right(fPath, 1) = "\", Mid(fPath, 1, Len(fPath) - 1), fPath)
sp = Split(fPath, "\"): strP$ = ""
Do While k < UBound(sp) + 1
strP$ = IIf(strP$ = "", sp(k), strP$ & "\" & sp(k))
If Dir(strP$, vbDirectory) = "" Then MkDir strP$
k = k + 1
Loop
End Sub

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网