+ Reply to Thread
Results 1 to 4 of 4

Deleting a file from within Excel

  1. #1
    Night Owl
    Guest

    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



  2. #2
    Alan
    Guest

    Re: Deleting a file from within Excel

    Try
    Application.DisplayAlerts=False
    'Your Filename'.Delete
    Application.DisplayAlerts=True
    Regards,
    Alan.
    "Night Owl" <[email protected]> wrote in message
    news:[email protected]...
    > 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
    >




  3. #3
    William
    Guest

    Re: Deleting a file from within Excel

    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
    [email protected]


    "Night Owl" <[email protected]> wrote in message
    news:[email protected]...
    > 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
    >




  4. #4
    Night Owl
    Guest

    Re: Deleting a file from within Excel

    Thanks, William.

    I'm sorted,

    Pete

    "William" <[email protected]> wrote in message
    news:[email protected]...
    > 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
    > [email protected]
    >
    >
    > "Night Owl" <[email protected]> wrote in message
    > news:[email protected]...
    >> 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
    >>

    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1