0
甚至出現我有下面的代碼有問題:MSGBOX當它不應該Excel VBA中
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,代碼也不會創建該目錄。
感謝
那麼它不會創建它,因爲它沒有開始。雖然我討厭這樣循環,但可以在vbYes if語句的末尾添加'GoTo 0'來啓動代碼。 – engineersmnky
你不應該使用'month/year'作爲變量。它們是vba –
中的保留名稱,第二個問題是即使選擇了vbyes,代碼也不會創建該目錄。「它不會創建它,因爲您沒有要求它。我沒有在那裏看到一個'MKDIR'聲明。 –