ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Deleting a file from within Excel (https://www.excelbanter.com/excel-worksheet-functions/26155-deleting-file-within-excel.html)

Night Owl

Deleting a file from within Excel
 
Hi,

I'm importing data from an external *.txt file, but don't want to duplicate
the data by importing the same file twice. When I'm doing it I'll remember
to delete the file after I've imported it, but when someone else does it
they may not.

So my question is this...

The filename and path are stored in the variable myFile - How can I delete
this file as the final step in the macro, without being prompted by a yes/no
option?

As an aside, I also get a prompt when I try to delete a non-active sheet
using code. Can I prevent that, too?

TIA,

Pete



Alan

Try
Application.DisplayAlerts=False
'Your Filename'.Delete
Application.DisplayAlerts=True
Regards,
Alan.
"Night Owl" wrote in message
...
Hi,

I'm importing data from an external *.txt file, but don't want to
duplicate the data by importing the same file twice. When I'm doing it
I'll remember to delete the file after I've imported it, but when someone
else does it they may not.

So my question is this...

The filename and path are stored in the variable myFile - How can I delete
this file as the final step in the macro, without being prompted by a
yes/no option?

As an aside, I also get a prompt when I try to delete a non-active sheet
using code. Can I prevent that, too?

TIA,

Pete




William

Hi Pete

Sub test()
'Assumes full path of file name
'to be deleted is in cell B2 and
'the file has been closed
Dim myFile As String
myFile = ThisWorkbook.Sheets("Sheet1").Range("B2")
Kill myFile
End Sub

Sub test1()
Application.DisplayAlerts = False
ThisWorkbook.Sheets("Sheet1").Delete
Application.DisplayAlerts = True
End Sub


--


XL2003
Regards

William



"Night Owl" wrote in message
...
Hi,

I'm importing data from an external *.txt file, but don't want to
duplicate the data by importing the same file twice. When I'm doing it
I'll remember to delete the file after I've imported it, but when someone
else does it they may not.

So my question is this...

The filename and path are stored in the variable myFile - How can I delete
this file as the final step in the macro, without being prompted by a
yes/no option?

As an aside, I also get a prompt when I try to delete a non-active sheet
using code. Can I prevent that, too?

TIA,

Pete




Night Owl

Thanks, William.

I'm sorted,

Pete

"William" wrote in message
...
Hi Pete

Sub test()
'Assumes full path of file name
'to be deleted is in cell B2 and
'the file has been closed
Dim myFile As String
myFile = ThisWorkbook.Sheets("Sheet1").Range("B2")
Kill myFile
End Sub

Sub test1()
Application.DisplayAlerts = False
ThisWorkbook.Sheets("Sheet1").Delete
Application.DisplayAlerts = True
End Sub


--


XL2003
Regards

William



"Night Owl" wrote in message
...
Hi,

I'm importing data from an external *.txt file, but don't want to
duplicate the data by importing the same file twice. When I'm doing it
I'll remember to delete the file after I've imported it, but when someone
else does it they may not.

So my question is this...

The filename and path are stored in the variable myFile - How can I
delete this file as the final step in the macro, without being prompted
by a yes/no option?

As an aside, I also get a prompt when I try to delete a non-active sheet
using code. Can I prevent that, too?

TIA,

Pete







All times are GMT +1. The time now is 11:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com