新浪博客

EXCEL VBA 生成文件夹(自动按树状目录)

2010-07-28 18:56阅读:
好久都没有碰过代码了,感觉很手生,呵呵,不过终究还是写出来了,拿出来大家分享,高手别喷。
JCG捷希智能无线专家。
EXCEL <wbr>VBA <wbr>生成文件夹(自动按树状目录)
因为有前面 几个合并的数据,所以程序麻烦了点。

Sub makfile()
Dim count, url, words, rwindex, url1, fso
Set fso = CreateObject('Scripting.FileSystemObject')
count = ActiveSheet.UsedRange.Rows.count 'rows
url = 'e:\wireless\'
For words = 1 To count
If Sheet1.Cells(words, 1).Value <> '' Then
url = url + Sheet1.Cells(words, 1).Value + '\'
Else
url1 = ''
wd1 = words
Do While url1 = ''
url1 = Sheet1.Cells(wd1 - 1, 1).Value
wd1 = wd1 - 1
Loop
url = url + url1 + '\'
End If
If fso.FolderExists(url) = False Then MkDir (url)

url1 = ''
If Sheet1.Cells(words, 2).Value <> '' Then
url = url + Sheet1.Cells(words, 2).Value + '\'
Else
wd1 = words
Do While url1 = ''
url1 = Sheet1.Cells(wd1 - 1, 2).Value
wd1 = wd1 - 1
Loop
url = url + url1 + '\'
End If
If fso.FolderExists(url) = False Then MkDir (url)

url = url + Sheet1.Cells(words, 3).Value
If fso.FolderExists(url) = False Then MkDir (url)
url = 'e:\wireless\'
Next words
End Sub

我的更多文章

下载客户端阅读体验更佳

APP专享