首页 > 解决方案 > 创建工作订单子文件夹以跟踪项目

问题描述

我使用 Excel 来跟踪我的项目。我在一个项目中收到多个工单。我需要在项目文件夹中创建多个文件夹。

我制定了一个宏来根据工单编号创建文件夹,但我需要工单文件夹中的子文件夹。

子文件夹保持不变,即输入和输出文件夹。
文件夹结构为项目文件夹>工单>输入和输出。

Sub Create_Folders()

Dim Rng As Range
Dim maxRows, maxCols, r, c As Integer
Dim path As Variant

Set Rng = Selection

maxRows = Rng.Rows.Count
maxCols = Rng.Columns.Count

For c = 1 To maxCols
    r = 1

    path = Application.InputBox("Enter the path where you want to create the folders", "Enter location")

    Do While r <= maxRows

        If Len(Dir(path & "\" & Rng(r, c), vbDirectory)) = 0 Then
            MkDir (path & "\" & Rng(r, c))
            On Error Resume Next
        End If

        r = r + 1
    Loop
Next c

End Sub

标签: excelvba

解决方案


Dim path As Variant, fpath$
'...
fpath = path & Application.PathSeparator & Rng(r, c).Text
If Len(Dir(fpath, vbDirectory)) = 0 Then
  MkDir fpath 'create main folder
  'create subfolders
  MkDir fpath & Application.PathSeparator & "Input"
  MkDir fpath & Application.PathSeparator & "Output"
  '...
End If

推荐阅读