Dear sirs
fix last code, if use "for" will cause error, need change "for each"
Sub check_menu()
Dim wb As Workbook
'ThisWorkbook.Path:傳回本工作簿、檔案所儲存的路徑。
'ThisWorkbook.FullName:傳回本工作簿、檔案所儲存的路徑 + 檔名。
'ThisWorkbook.Name:傳回本工作簿、檔案所儲存的檔名。
'ActiveWindow.ActiveSheet.Name 或 ActiveSheet.Name 目前工作表名稱
work_book = ThisWorkbook.Name
'檔案檢查
If Dir("C:\stock", vbDirectory) = "" Then MkDir "C:\stock"
If Dir("C:\stock\analysis", vbDirectory) = "" Then MkDir "C:\stock\analysis"
If Dir("C:\stock\data", vbDirectory) = "" Then MkDir "C:\stock\data"
For each wb in application.workbooks
if Right(wb.Name, 4) = ".csv" or Right(wb.Name, 4) = "csv" then
Application.DisplayAlerts = False
wb.Close (vb = yes)
Application.DisplayAlerts = True
elseIf Right (wb.Name, 5) = ".xlsx" or Right(wb.Name, 5) = "xlsx" then
Application.DisplayAlerts = False
wb.Close (vb = yes)
Application.DisplayAlerts = True
End If
Next wb
'舊檔案刪除
If Len(Dir("C:\stock\*.*")) > 0 Then Kill "C:\stock\*.*"
'SetAttr "C:\stock\*.*", vbNormal ' 排除唯讀檔問題
If Len(Dir("C:\stock\data\*.*")) > 0 Then Kill "C:\stock\data\*.*"
'SetAttr "C:\stock\data\*.*", vbNormal ' 排除唯讀檔問題
If Len(Dir("C:\stock\analysis\*.*")) > 0 Then Kill "C:\stock\analysis\*.*"
'SetAttr "C:\stock\analysis\*.*", vbNormal ' 排除唯讀檔問題
Main_Menu (work_book)
End Sub