path名中的variables和获取path未find错误

我正在拉我的头发。 mkdir与年份(整数)一起工作,但不能与月份(string)相加。

year = 2013 month = MonthName(1) 'I have also tried just putting "January" in there as well 

这工作:

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

但是这不是:

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

build议? 谢谢!

最终修正:

将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 

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

所以扩展你的发布代码,你可以这样做:

 Path1 = "\\TEST\" & year & "\" If DIR$(Path1, vbDirectory) <> "" then mkdir Path1 Path1 = "\\TEST\" & year & "\" & month & "\" If DIR$(Path1, vbDirectory) <> "" then mkdir Path1