Re: Excel VBA to move file to recycle bin
First, I would like to thank you for replying to my inquiry so fast and with very detail instruction and explanation. Needless to say, I am very new at these VBA stuffs, and literally exhausted looking for answer to my problem. I am very handicap in many ways: English barrier, computer illiterate, etc. This is what I have in my worksheet: a HYPERLINK column to link 1,300 presentation files (extension ppt.) in a desktop folder, and a column where the VALUE of the hyperlink's data is pasted (the title of the presentation.). So when I click on the hyperlink, the linked file is opened. What I would like to do is: there is a way I can open the folder and go straight to the file where is located and be able to delete.
Thru searching from the internet & YouTube video, I have managed to have the following code written. There is a manual step in this deleting process that I am looking for help. So hopefully I no longer have to do this step manually anymore. The manual step, I have to go to the column where the value I stored (the complete name of the linked file), and copy "that information" so when I run the code, the dialog prompt come up, I then paste the info by hitting Ctr +V. (I might know how to copy the value, and use the keyboard shortcut key "to paste", but other user might not know. and I am sharing this work with other people.) So is there a way, a code or function could be written so that when I click on the cell where I want the file to be deleted, the "computer" could look at that as "Target Cell" and copy the value or the info in that cell without having me to copy and paste the info in the prompt dialog box? Here is the code I got:
Sub TestToDeleteFile() Dim fso As Scripting.FileSystemObject Dim file As String Dim FileName As String FileName = InputBox("Name") file = Environ("userprofile") & "\desktop\bss" & FileName Set fso = CreateObject("Scripting.FileSystemObject") If fso.FileExists(file) Then MsgBox "FOUND and DELETE" fso.DeleteFile file, True Else MsgBox file & " does not exist or has already been deleted!" _ , vbExclamation, "File not Found" End If End Sub