返回列表 上一主題 發帖

[發問] 請問刪除資料夾內的所有*.xls

回復 2# HSIEN6001
  1. Option Explicit
  2. Sub Ex()
  3.     Kill "D:\*.xls"
  4. End Sub
  5. Sub Ex1()
  6.     Dim Fs As Object, xPath As String, xFile As String
  7.     Set Fs = CreateObject("Scripting.FileSystemObject")
  8.     xPath = "D:\"
  9.     xFile = Dir(xPath & "*.xls")
  10.     Do
  11.         If xFile <> "" Then
  12.         Fs.DeleteFile xPath & xFile
  13.         xFile = Dir
  14.         End If
  15.     Loop While xFile <> ""
  16. End Sub
複製代碼

TOP

回復 5# freeffly
是一樣的 Ex1可簡化 如 Ex
  1. Option Explicit
  2. Sub Ex()
  3.     On Error Resume Next    '有錯誤時不理會它, 繼續下一行程式碼
  4.     Kill "D:\*.xls"                      '找不到檔案時會有錯誤
  5. End Sub
  6. Sub Ex1()
  7.     Dim Fs As Object, xFile As String
  8.     On Error Resume Next    '有錯誤時不理會它, 繼續下一行程式碼
  9.     Set Fs = CreateObject("Scripting.FileSystemObject")
  10.     xFile = "D:\*.xls"
  11.     Fs.DeleteFile xFile     '找不到檔案時會有錯誤
  12. End Sub
複製代碼

TOP

        靜思自在 : 能付出愛心就是福,能消除煩惱就是慧。
返回列表 上一主題