How to close all .csv or .xlsx type file
Hi sirs
i want to close all csv and xlsx type file, when i restart program. i use * to filter, but it looks some problem... please give me some suggest, thanks.
Code:
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 file_check = 1 To Workbooks.Count
If Workbooks(file_check).Name = "*.csv" Then
Windows("*.csv").Activate
Application.DisplayAlerts = False
Windows("*.csv").Close (vb = yes)
Application.DisplayAlerts = True
End If
Next file_check
For file_check = 1 To Workbooks.Count
If Workbooks(file_check).Name = "*.xlsx" Then
Windows("*.xlsx").Activate
Application.DisplayAlerts = False
Windows("*.xlsx").Close (vb = no)
Application.DisplayAlerts = True
End If
Next file_check
'舊檔案刪除
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 ' 排除唯讀檔問題
End Sub