Help with "Kill" command

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
361
Office Version
  1. 2007
Platform
  1. Windows
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.
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.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Delete the quotes. It's already a string; you don't want quotes to be part of the string.

VBA Code:
Dim aFile As String
  aFile = Range("T5").Text & Range("V6").Text
  Kill aFile
 
Upvote 0
Solution

Forum statistics

Threads
1,221,417
Messages
6,159,789
Members
451,589
Latest member
Harold14

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top