Help with "Kill" command

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
407
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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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
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

Thank you Jeff. That worked perfect - how silly of me.
 
Upvote 1

Forum statistics

Threads
1,223,885
Messages
6,175,186
Members
452,615
Latest member
bogeys2birdies

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