VBA之获取目录(一)

    xiaoxiao2025-04-09  35

    例子

    [01]一级目录

          [02]二级目录

                 [3]三级目录

                      内容1

                      内容2

    ..............................................

    ...............................................

    如何使用vba来获取以上的目录呢?

    Sub main() Dim line As Integer Dim row As Integer dic_index = 0 row = 1 For line = 0 To 16 line = line + 1 If Worksheets("sheet1").Cells(line, row) = "" And Worksheets("sheet1").Cells(line, row + 1) = "" Then row = getback(line, row, dic_index) line = line - 1 End If If Worksheets("sheet1").Cells(line, row) = "" And Worksheets("sheet1").Cells(line, row + 1) <> "" Then row = row + 1 line = line - 1 End If If Worksheets("sheet1").Cells(line, row) <> "" Then dic_arr(dic_index) = Worksheets("sheet1").Cells(line, row) dic_index = dic_index + 1 If Worksheets("sheet1").Cells(line + 1, row + 1) <> "" Then If Worksheets("sheet1").Cells(line + 2, row + 2) <> "" Then 'diction requary End If End If Else 'cope data End If Next End Sub Function getback(line As Integer, row As Integer, dic_index As String) Do While Worksheets("sheet1").Cells(line, row) = "" row = row - 1 dic_index = dic_index - 1 Loop row = getback End Function

    以上代码参考

    最新回复(0)