0

我正在拔头发。mkdir 适用于年份(整数),但不适用于添加的月份(字符串)。

year = 2013
month = MonthName(1)

'I have also tried just putting "January" in there as well

这有效:

Path1 = "\\TEST\" & year & "\" 

但这不会:

Path1 = "\\TEST\" & year & "\" & month & "\"

建议?谢谢!

最终修复:

将 Path1 拆分为:

Path1: "\\TEST\" & year & "\"

Path2:  "\\TEST\" & year & "\" & month & "\"

通过检查:

If Len(Dir(Path1, vbDirectory)) = 0 Then
        MkDir Path1
End If
If Len(Dir(Path2, vbDirectory)) = 0 Then
        MkDir Path2
End If
4

1 回答 1

2

除非已经存在,否则"\\TEST\" & year & "\" & month & "\"不能通过MkDir创建。"\\TEST\" & year & "\"

因此,扩展您发布的代码,您可以这样做:

Path1 = "\\TEST\" & year & "\"
If DIR$(Path1, vbDirectory) <> "" then mkdir Path1
Path1 = "\\TEST\" & year & "\" & month & "\"
If DIR$(Path1, vbDirectory) <> "" then mkdir Path1
于 2013-01-02T18:57:19.500 回答