- 帖子
- 7
- 主題
- 2
- 精華
- 0
- 積分
- 7
- 點名
- 0
- 作業系統
- Win10
- 軟體版本
- Win10
- 閱讀權限
- 10
- 註冊時間
- 2021-1-11
- 最後登錄
- 2021-4-17
|
請問加入了資料夾建置判斷式,導致"執行時間錯誤5"這個問題,是哪邊流程出了狀況呢?
If Len(Dir(sPath & "Result", vbDirectory)) = 0 Then
MkDir sPath & "Result"
End If
完整code
b = True
Application.DisplayAlerts = False
Application.ScreenUpdating = False
sPath = "C:\Users\Desktop\daliy report demo test_1\"
sFile = Dir(sPath & "\*.xlsx")
Do While sFile <> ""
Workbooks.Open sPath & "\" & sFile, UpdateLinks:=0
If i <> 1 Then
'If Len(Dir(sPath & "Result", vbDirectory)) = 0 Then
MkDir sPath & "Result"
' End If
Sheets(1).Copy
ActiveWorkbook.SaveAs sPath & "Result" & "\" & Format(Date, "mmdd") & "Result.xlsx"
i = 1 '第一次開啟
Workbooks(sFile).Close
Else
Sheets(1).Copy After:=Workbooks(Format(Date, "mmdd") & "Result.xlsx").Sheets(1)
Worksheets(2).Name = "Sheet2"
Call compare
Worksheets(2).Delete
Workbooks(sFile).Close
End If
sFile = Dir()
Loop
Workbooks(Format(Date, "mmdd") & "Result.xlsx").Close SaveChanges:=True |
|