如何编写代码以使用VBA根据用户输入的文件名删除文件?

时间:2019-10-11 03:14:52

标签: excel vba

userinput = InputBox(Prompt:="Please key in the file name and format", Title:=" File name", Default:=".xlsm") 'This is Your File Name which you want to Copy
sSFolder = "J:\Inter Dept\MP8 Packaging\2.0 MP8.1\B2-Machine Data Tracking\B2-Machine Data Tracking 2019\" 'Change to match the source folder path
sDFolder = "C:\Users\limmigmy\Desktop\Rejection Report\Rejection\Packing Analysis\Production Files\" & "userinput" 'Change to match the destination folder path

Set FSO = CreateObject("Scripting.FileSystemObject") 'Create Object

If FSO.filexists(sDFolder) Then
    FSO.DeleteFile sDFolder, True
    MsgBox "Deleted The File Successfully", vbInformation, "Done!" 'If file exists, It will delete the file from source location
    Else
    MsgBox "Specified File Not Found", vbInformation, "Not Found!" 'If file does not exists, It will display following message
    End If

0 个答案:

没有答案