Hello,
I’m having a problem with the syntax of the “Kill” command. I’m trying to delete a file on my local drive via VBA. I can hardcode in the path\filename and all works fine. However, the path and filename may change. Therefore, I’ve been attempting to do so with variables.
If I use this hardcoded routine it works fine:
Kill "C:\Users\<username>\Desktop\2001.xlsb"
Because the path\filename may change, I’d like to do something like this:
Note: cell “T5” contains the path; “V6” contains the filename.
However, this returns a Run-time error 53 File not found.
I know the file is there. As a test to see if my aFile code is correct I tried the following:
This worked fine as Cell “Q29” displayed:
"C:\Users\<username>\Desktop\2001.xlsb"
Which I believe is correct.
Any suggestions would be appreciated and thanks for viewing,
Steve K.
I’m having a problem with the syntax of the “Kill” command. I’m trying to delete a file on my local drive via VBA. I can hardcode in the path\filename and all works fine. However, the path and filename may change. Therefore, I’ve been attempting to do so with variables.
If I use this hardcoded routine it works fine:
Kill "C:\Users\<username>\Desktop\2001.xlsb"
Because the path\filename may change, I’d like to do something like this:
Note: cell “T5” contains the path; “V6” contains the filename.
VBA Code:
Dim aFile As String
aFile = """" & Range("T5").Text & Range("V6").Text & """"
Kill aFile
However, this returns a Run-time error 53 File not found.
I know the file is there. As a test to see if my aFile code is correct I tried the following:
Code:
Dim aFile As String
aFile = """" & Range("T5").Text & Range("V6").Text & """"
Range("Q29") = aFile
This worked fine as Cell “Q29” displayed:
"C:\Users\<username>\Desktop\2001.xlsb"
Which I believe is correct.
Any suggestions would be appreciated and thanks for viewing,
Steve K.