Aretradeser
Board Regular
- Joined
- Jan 16, 2013
- Messages
- 176
- Office Version
- 2013
- Platform
- Windows
I use Microsoft® Excel for Mac, Version 16.83 (24031120), Office LTSC Standard for Mac 2021.
I have designed a code to open a dialog box and allow me to select any file; and, once selected, to give me the option to move it to the trash. Everything seems to work correctly showing, via a screen, that; "The file has been moved to the trash successfully." But it hasn't actually moved it to the bin, it's still in the same place.
How can I fix this problem and have it actually move /Delete the file I have selected?
This is the code:
I have designed a code to open a dialog box and allow me to select any file; and, once selected, to give me the option to move it to the trash. Everything seems to work correctly showing, via a screen, that; "The file has been moved to the trash successfully." But it hasn't actually moved it to the bin, it's still in the same place.
How can I fix this problem and have it actually move /Delete the file I have selected?
This is the code:
VBA Code:
Sub SelectAndDeleteFile()
Dim RutaArchivo As String
Dim Respuesta As Integer
' Select file
RutaArchivo = MacScript("return POSIX path of (choose file)")
If RutaArchivo <> "" Then
Respuesta = MsgBox("¿Surely you want to move the file to the trash?", vbYesNo + vbQuestion, "Confirmation")
If Respuesta = vbYes Then
On Error Resume Next
Kill RutaArchivo ' Delete the file (move to trash)
If Err.Number = 0 Then
MsgBox "The file has been successfully moved to the Trash..", vbInformation, "File Deleted"
Else
MsgBox "Failed to move file to trash.", vbExclamation, "Error"
End If
On Error GoTo 0
End If
End If
End Sub