+ Reply to Thread
Results 1 to 11 of 11

Thread: Deleting on files via Excel macro

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

    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 Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Deleting on files via Excel macro

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

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

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

    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
    61

    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?:

    Kill "http://Intranet/cornerstone/Cornerstone Reports/Town Reports/*.xls"

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

    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
    61

    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:

    FileCopy "foldername\Combined Town Report 00-00-11.xlsx", "foldername\_OLD\" & "Combined Town Report " & Format(Now, "dd-mm-yy") & ".xlsx"
    But this doesn't:

    FileCopy "foldername\Combined Town Report 00-00-11.xlsx", "http://Intranet\cornerstone\Cornerstone%20Reports\Town%20Reports\" & "Combined Town Report " & Format(Now, "dd-mm-yy") & ".xlsx"

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

    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
    61

    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 Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Deleting on files via Excel macro

    I suspect it's to prevent malicious deleteing
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

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

    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
    61

    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.2.0