+ Reply to Thread
Results 1 to 11 of 11

Deleting on files via Excel macro

  1. #1
    Registered User
    Join Date
    02-08-2005
    Location
    Kent, UK
    MS-Off Ver
    2010
    Posts
    69

    Deleting on files via Excel macro

    As I can save a new file with today's date is there a way to delete or move the old file already in the folder? The file name will be in the same format but the date would be different though in the same format, e.g. 25-07-11. Is there anyway the macro could find this old file and delete it or move it?

    I see backups of all reports on our network but generally only keep the latest file on our intranet, so I would need to delete the old file on our intranet and move the old file on our network.

    Relating post is here.
    Last edited by koltregaskes; 08-17-2011 at 11:34 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Deleting on files via Excel macro

    Use the Kill command, read the vba help files
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    02-08-2005
    Location
    Kent, UK
    MS-Off Ver
    2010
    Posts
    69

    Re: Deleting on files via Excel macro

    Thank you. How do wildcards work in the Kill statement?

    I'd like to delete all files starting with "Combined Town Report" and end with ".xlsx". The bit in the middle is normally the date which differs each day. How would I do this? Every variation I can think of doesn't appear to work.

  4. #4
    Registered User
    Join Date
    02-08-2005
    Location
    Kent, UK
    MS-Off Ver
    2010
    Posts
    69

    Re: Deleting on files via Excel macro

    An additional question to above. I've tried deleting all .XLS files in a folder on our intranet with the following code but I get the error sayign file not found. What am I doing wrong?:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-08-2005
    Location
    Kent, UK
    MS-Off Ver
    2010
    Posts
    69

    Re: Deleting on files via Excel macro

    And yes there are .xls files in the folder. :-)

  6. #6
    Registered User
    Join Date
    02-08-2005
    Location
    Kent, UK
    MS-Off Ver
    2010
    Posts
    69

    Re: Deleting on files via Excel macro

    OK, it seems I cannot save or delete anything on that intranet (http) addresses in an Excel macro. Is this correct?

    Basically this code works:

    Please Login or Register  to view this content.
    But this doesn't:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-08-2005
    Location
    Kent, UK
    MS-Off Ver
    2010
    Posts
    69

    Re: Deleting on files via Excel macro

    Any thoughts on why the Kill command will not work with intranet/internet links? FlieCopy also doesn't appear to work.

    The error is bad file but the code is exactly the same apart from being online.

  8. #8
    Registered User
    Join Date
    02-08-2005
    Location
    Kent, UK
    MS-Off Ver
    2010
    Posts
    69

    Re: Deleting on files via Excel macro

    Anyone know why FileCopy and Kill commands don't appear to work on intranet/Internet addresses?

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Deleting on files via Excel macro

    I suspect it's to prevent malicious deleteing

  10. #10
    Registered User
    Join Date
    02-08-2005
    Location
    Kent, UK
    MS-Off Ver
    2010
    Posts
    69

    Re: Deleting on files via Excel macro

    Right, shame that as it means the marcro will need some manual work still. Ta for the reply.

  11. #11
    Registered User
    Join Date
    02-08-2005
    Location
    Kent, UK
    MS-Off Ver
    2010
    Posts
    69

    Re: Deleting on files via Excel macro

    I've found a solution to this, at least for me. I can change the http addresses to \\intranet\ addresses.

    Kill and FileCopy commands seem to work with this type of address. Pretty simple in the end.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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