Deleting a hyperlinks file

I have a hyperlink with a cell that points to a file on my local computer.  How can I delete the file that the hyperlinks points to?

Thank you.
thandelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zorvek (Kevin Jones)ConsultantCommented:
Locate the file using Windows File Explorer, select it, and press DELETE.

Kevin
thandelAuthor Commented:
Well I wanted to write a macro hence the reason I am asking the question.

I would like the macro to delete the file based on the active cell's link.  

Sorry I thought I was clear that a macro was needed and File Deletion 101 wasn't preferred.
zorvek (Kevin Jones)ConsultantCommented:
Sorry...

Kill [A1].Hyperlinks(1).Address

Kevin

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

thandelAuthor Commented:
No worries...

Is it possible to use something like kill ActiveCell.Hyperlinks(1).Address  as I would like to run the macro for what ever the active cell is selected.
thandelAuthor Commented:
Nevermind that worked.  Thanks!
zorvek (Kevin Jones)ConsultantCommented:
Sure, but put some error handling in case there is no hyperlink.

   On Error Resume Next
   Kill ActiveCell.Hyperlinks(1).Address
   On Error GoTo 0

Kevin
thandelAuthor Commented:
Opps reacting too quick... when I try to run it I'm getting the following error:

Run time error '53' file not found.

However when I select the link the file opens, so the link is present and the file is present.  Any ideas?
zorvek (Kevin Jones)ConsultantCommented:
I want to ask if the link really points to a file but that would be a pretty stupid question at this point :-)

Just for fun, run this code and post what the message box says. Also post the full path to the file. Maybe there is some default/current folder stuff going on...

   MsgBox ActiveCell.Hyperlinks(1).Address

Kevin
thandelAuthor Commented:
../../Desktop/BETA/beta.txt

zorvek (Kevin Jones)ConsultantCommented:
I can't make my tests fail. Both the Kill and the follow hyperlink functions use the workbook's directory to locate the file. In other words, no matter what I do I can't make one fail and the other not.

What version of Excel are you using?

Kevin
thandelAuthor Commented:
Excell 2003.  Excel is adding the ../../ since the file I"ve selected is not in the same folder as the spreadsheet.  If I place the file in the same folder and use:

Kill ActiveWorkbook.Path & "\" & ActiveCell.Hyperlinks(1).Address


zorvek (Kevin Jones)ConsultantCommented:
Oops...my test was bad...

This should work:

   ChDir ActiveWorkbook.Path
   On Error Resume Next
   Kill ActiveCell.Hyperlinks(1).Address
   On Error GoTo 0

Turns out Kill uses the current directory while the follow hyperlink function uses the workbook's directory.

Kevin
thandelAuthor Commented:
The above will not work as the file I'm trying to delete is NOT in the same directory as the workbook. (or the current directory)
zorvek (Kevin Jones)ConsultantCommented:
Right. But the follow hyperlink works from the workbook's directory. So if the follow hyperlink function can find it then the above code will work. Take your original example:

../../Desktop/BETA/beta.txt

Assuming the workbook is two levels deeper than Desktop then, by setting the current directory to the workbook's folder, Kill will move up two directories and then down to BETA to find beta.txt.

Remember we are trying to emulate the same path scheme that the follow hyperlinks function uses.

Kevin
thandelAuthor Commented:
Works!   Thanks.... you are awesome at this stuff.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.