我遇到以下代码问题:
month = Me.monthcbg.Value
year = Me.yrcbg.Value
If Len(Dir("L:\NAI_Groups\IS Monthly Operations Meeting\" & year, vbDirectory)) = 0 Then
MkDir "L:\NAI_Groups\IS Monthly Operations Meeting\" & year
End If
If Len(Dir("L:\NAI_Groups\IS Monthly Operations Meeting\" & year & "\" & month, vbDirectory)) = 0 Then
MkDir "L:\NAI_Groups\IS Monthly Operations Meeting\" & year & "\" & month
MkDir "L:\NAI_Groups\IS Monthly Operations Meeting\" & year & "\" & month & "\1_LOP"
MkDir "L:\NAI_Groups\IS Monthly Operations Meeting\" & year & "\" & month & "\2_Plants_Operations"
MkDir "L:\NAI_Groups\IS Monthly Operations Meeting\" & year & "\" & month & "\3_Logistics_Purchasing_IT"
MkDir "L:\NAI_Groups\IS Monthly Operations Meeting\" & year & "\" & month & "\4_Development_Changes"
ElseIf Len(Dir("L:\NAI_Groups\IS Monthly Operations Meeting\" & year & "\" & month, vbDirectory)) <> 0 Then
mes = MsgBox("A presentation already exists, would you like to overwrite the existing presentation?", vbYesNo, "Presentation Exists")
If mes = vbNo Then
Exit Sub
ElseIf mes = vbYes Then
On Error Resume Next
Kill "L:\NAI_Groups\IS Monthly Operations Meeting\" & year & "\" & month & "\1_LOP\" & month & "\" & year & ".pptx"
MsgBox "Old Presentation Deleted"
Set Error = 0
End If
End If
月份和年份的尺寸为字符串。第一个问题是,即使没有现有目录,msgbox也会一直出现,第二个问题是即使选择了vbyes,代码也不会创建目录。
谢谢
答案 0 :(得分:0)
我实际上没有看到代码的问题,但我已经清理了一下
Dim root_dir As String
Dim sub_dir(3) AS String
month_str = Me.monthcbg.Value
year_str = Me.yrcbg.Value
root_dir = "L:\NAI_Groups\IS Monthly Operations Meeting\" & year_str
sub_dir(0) = "\1_LOP"
sub_dir(1) = "\2_Plants_Operations"
sub_dir(2) = "\3_Logistics_Purchasing_IT"
sub_dir(3) = "\4_Development_Changes"
If Len(Dir(root_dir, vbDirectory)) = 0 Then MkDir root_dir
If Len(Dir( root_dir "\" & month_str, vbDirectory)) = 0 Then
MkDir root_dir & "\" & month_str
For i =0 to UBound(sub_dir) -1
MkDir root_dir & "\" & month_str & "\" & sub_dir(i)
Next i
Else
mes = MsgBox("A presentation already exists, would you like to overwrite the existing presentation?", vbYesNo, "Presentation Exists")
If mes = vbNo Then
Exit Sub
ElseIf mes = vbYes Then
On Error Resume Next
Kill root_dir & "\" & month_str & "\1_LOP\" & month_str & "\" & year_str & ".pptx"
MsgBox "Old Presentation Deleted"
Set Error = 0
Goto 0
End If
End If