老师,在冒昧的问下word用日期生成的文件夹用代码怎么查找
比如,我自动在F盘生成了一个名为“1”的文件夹,
又在“1”的文件夹里用日期自动生成一个“2016年12月”文件夹
问题:我现在又想在“2016年12月”自动生成一个文件夹怎么办,“2016年12月”这个文件夹代码路径我不知道用什么来写。如下:
Dim mypath As String, a As String, n As Integer, myname As String
mypath = "F:\" & VBA.Format(1) ‘自动生成名字为1的文件夹
If Dir(mypath, vbDirectory) = "" Then VBA.MkDir mypath
ChDrive mypath
ChDir mypath
mypath = "F:\1\" & VBA.Format(Date, "yyyy年mm月") ’自动生成名字为2016年12月的文件夹
If Dir(mypath, vbDirectory) = "" Then VBA.MkDir mypath
ChDrive mypath
ChDir mypath
‘如下,前面两个文件夹都有路径自动生成,而这下面这个路径是?yyyy年mm月 这个要怎么写
mypath = "F: \1\ 这里要怎么表示,或是还有其它方法 \" & VBA.Format(Date, "yyyy年mm月dd日")
If Dir(mypath, vbDirectory) = "" Then VBA.MkDir mypath
ChDrive mypath
ChDir mypath
在线等了,谢谢。
最佳答案
就是建立多层文件夹吧?如下供参考:
'假设的文件夹、子文件夹的名称为:
fold1 = "F:\" & 1
fold2 = Format(Date, "yyyy年mm月")
fold3 = "ABCD"
'F盘,生成名字为1的文件夹
mypath = fold1
If Dir(mypath, vbDirectory) = "" Then
MkDir mypath
End If
'F:\1\下,生成名字为2016年12月的文件夹
mypath = fold1 & "\" & fold2
If Dir(mypath, vbDirectory) = "" Then
MkDir mypath
End If
'F:\1\2016年12月\下,生成名字为ABCD的文件夹
mypath = fold1 & "\" & fold2 & "\" & fold3
If Dir(mypath, vbDirectory) = "" Then
MkDir mypath
End If
'F:\1\2016年12月\ABCD\下,生成名字为001、002、003的三个文件夹
For i = 1 To 3
mypath = fold1 & "\" & fold2 & "\" & fold3 & "\" & Right("000" & i, 3)
If Dir(mypath, vbDirectory) = "" Then
MkDir mypath
End If
Next
其他回答
暂无其它回答!