TkdKidSnake
Board Regular
- Joined
- Nov 27, 2012
- Messages
- 245
- Office Version
- 365
- Platform
- Windows
Hi all,
I am trying to come up with some code to delete a file in a location that I know exists as the file creates this before the need to delete the file, the filename is created and is store in cell i1 - see the code I have below unfortunetely I keep getting an error. If anyone can help it would be greatly appreciated.
Any help can provide would be greatly appreciated.
Regards
Steve
I am trying to come up with some code to delete a file in a location that I know exists as the file creates this before the need to delete the file, the filename is created and is store in cell i1 - see the code I have below unfortunetely I keep getting an error. If anyone can help it would be greatly appreciated.
VBA Code:
Sub KillXLSM()
Application.DisplayAlerts = False
Dim usrnme As String
'Get username
usrnme = Environ("username")
Sheets("123").Visible = True
Sheets("123").Select
ActiveSheet.Unprotect
Dim myFolderName As String
Dim myFileName As String
' Build folder name
myFolderName = Environ("userprofile") & "\Desktop\123 Submission Docs\"
' Build file name
myFileName = Range("i1") & ".xlsm"
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False
ActiveWindow.SelectedSheets.Visible = False
' Kill file
Kill FileName:=myFolderName & myFileName
Application.DisplayAlerts = True
End Sub
Any help can provide would be greatly appreciated.
Regards
Steve