我有很多项目,无论项目是否完成,我都必须不断更新工作表中的状态,而且很多时候我都忘记这样做了。之后,我一头接一个地检查每个项目变得很头疼。
我将“项目完成”文件放在网络目录“ //172.56.12.142/09。Visualization / 04。@ LegacyProjects /”中。
现在,我要解决此问题的逻辑是运行一个宏,该宏将让我选择写在A列中的城市名称,然后在每个选定的单元格上进行迭代以检查我的目录中是否包含一组子带有城市名称的文件夹。(/ 03 Production Done / city_name_from_selected_cell /)。
如果存在这组子文件夹,则应将下一列(B)的值更新为“已完成”,否则更新为“进行中”。
我找到了一些代码,并如下进行了更改。
Sub Status()
Application.ScreenUpdating = False
Dim fso As Object
Dim folder As Object
Dim subfolders As Object
Dim subfolder1 As Object
Dim Rg As Range
Dim xStatus As String
Dim xCell As Range
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder("//172.56.12.142/09. Visualization/04. @LegacyProjects/")
Set subfolders = folder.subfolders
Set Rg = Application.InputBox("Please select city/cities to check production status!!!", "By Lmtools", Application.ActiveCell.Address, , , , , 8)
On Error GoTo 0
If Rg Is Nothing Then Exit Sub
For Each xCell In Rg
If xCell.Value <> "" Then
For Each subfolder1 In subfolders
xStatus = subfolder1.path
If xStatus Like "*?/03. Production_Done/" & xCell.Value & "/?*" Then
Cells(xCell.Row, xCell.Column + 1).Value = "Completed"
Else
Cells(xCell.Row, xCell.Column + 1).Value = "Ongoing"
End If
Next
End If
Next
Application.ScreenUpdating = True
End Sub
但是此代码不起作用。请帮忙!