Using Microsoft Access 2003 VBA Code to delete an Excel Workbook

Posted on 2011-04-27
Last Modified: 2012-08-13
I have a button on a form in my DB that creates an Excel Spreadsheet to display data to the end user. It saves this Excel file on the local hard drive in a specific location. After the user closes it, the data is no longer useful.  Before the user runs the next instance of this, I would like Access to delete the previous Excel file before creating the new one.

The path and file name are always a constant, so they can be specified on the script.  For specific reasons, I do not want the script to just overwrite the previous file the next time the user runs it.  I need to have it deleted.  Is there VBA Code I can add at the beginning of my script to delete the file first?  
Question by:jmcclosk
    LVL 33

    Accepted Solution

    Just like this:

    Kill  "C:\YourFolder\YourFileName.xls"

    Author Closing Comment

    Thank you!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
    Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now