VBA刪除當前檔案目錄下的檔案

時間 2022-01-06 13:15:03

1樓:設計複雜

1、首先在工作表中,點選選單欄【開發工具】,在其工具欄裡,點選【visual basic】,進入vba介面。

2、然後在vba介面,點選選單欄【插入】,在其下拉選單中,點選【模組】。

3、會彈出**編輯視窗,在**編輯視窗,輸入下**。

4、未執行**前,f盤目錄下有「789.xlsx」檔案。

5、在vba介面,點選執行按鈕,會發現f目錄下,「789.xlsx」檔案被成功刪除了。

2樓:姓王的

【之前】是資料夾,**中少了一個"\"

filename = dir(thisworkbook.path & "\之前\" & range("c2") & range("d2") & "檔案.xls")

3樓:大吉祥

thisworkbook.path & "\檔名(包括副檔名,如xls等)"加上「.delete」

4樓:我是真的少校

1)、vb語句:kill

sub deletefile()

dim strfile as string

strfile = thisworkbook.path & "\temp.xls"

kill strfile

end sub

sub deletefile2()

dim strfile as string

strfile = thisworkbook.path & "\temp.xls"

if dir(strfile) = "" then

msgbox strfile & " does not exists", vbcritical

else

kill strfile

end if

end sub

2)、filesystemobject物件:deletefile方法

sub deletefile_fso()

dim fso as filesystemobject

dim strfile as string

strfile = thisworkbook.path & "\test.xls"

set fso = new filesystemobject

if fso.fileexists(strfile) then

fso.deletefile strfile

else

msgbox strfile & " does not exists"

end if

set fso = nothing

end sub

怎麼用批處理刪除當前目錄下所有文字檔案中指定字串之前的內容

批處理檔案放你那當前目錄下,假定要找的字串是abcd,執行後將把在此之前的所有內容 包括本行之前的及上面所有行 刪去,未找到這字串的文字則不動 set str abcd for f delims i in findstr m i str txt do for f tokens 1 delims j ...

如何獲取目錄下的檔案數,如何獲取目錄下的檔案數(一行Python)

遞迴獲取本資料夾 包括子資料夾 中的檔案 int countdirectory cstring path 如何獲取目錄下的檔案數 一行python 如果想把該目錄下所有的檔案都統計出來,包括子目錄 子目錄的子目錄。可以使用os.walk來找出目錄下所有的檔案 import os print sum ...

C中怎樣同時獲取目錄下的目錄與檔案

獲得目錄下所有目錄 string dirs directory.getdirectories 你的目錄的完整路徑,searchoption.alldirectories 獲得目錄下所有檔案 string dirs directory.getdirectories 你的目錄的完整路徑,searchop...