从电子表格数据创建文件夹层次 [英] Create folder hierarchy from spreadsheet data
本文介绍了从电子表格数据创建文件夹层次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有几个电子表格,从左到右组织数据,我想从中创建文件夹。每个记录都没有空格,除非是行的末尾,所以我正在拍摄以下内容:
I have several spreadsheets with data organized from left to right which I would like to create folders from. Every record is complete with no blanks unless that is the end of the row, so I am shooting for something the following:
Col1 Col2 Col3
------ ------ ------
Car Toyota Camry
Car Toyota Corolla
Truck Toyota Tacoma
Car Toyota Yaris
Car Ford Focus
Car Ford Fusion
Truck Ford F150
Car
Toyota
Camry
Corolla
Yaris
Ford
Focus
Fusion
Truck
Toyota
Tacoma
Ford
F-150
...
唯一要注意的是我有大约15列,一些条目结束在第3列或第4列,因此只需要创建这些文件夹。
The only caveat to this would be that I have about 15 columns, and some of the entries end at column 3 or 4, and so only those folders need to be created.
有人可以帮助这个请求吗?我不是编程的陌生人,但我仍然是VBA新手。
Can anyone help with this request? I'm no stranger to programming, but I'm still pretty new with VBA.
谢谢!
推荐答案
Sub Tester()
Const ROOT_FOLDER = "C:\TEMP\"
Dim rng As Range, rw As Range, c As Range
Dim sPath As String, tmp As String
Set rng = Selection
For Each rw In rng.Rows
sPath = ROOT_FOLDER
For Each c In rw.Cells
tmp = Trim(c.Value)
If Len(tmp) = 0 Then
Exit For
Else
sPath = sPath & tmp & "\"
If Len(Dir(sPath, vbDirectory)) = 0 Then MkDir sPath
End If
Next c
Next rw
End Sub
这篇关于从电子表格数据创建文件夹层次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文