+ Reply to Thread
Results 1 to 5 of 5

SaveAs and Kill filename

  1. #1
    Forum Contributor
    Join Date
    08-20-2012
    Location
    London,England
    MS-Off Ver
    Excel 2010
    Posts
    184

    SaveAs and Kill filename

    Hi

    I am having a bit of trouble with the below code. When I am killing the filename, there will always be two variations of the existing filename so I have added an error handler ie 'if the first file name doesn't exist, then try this one'.

    This is a bit sloppy and I am getting an error 'Run-Time error '53': File not found' even if it has found the file and killed it. (The XXXXX is the filepath which I have redacted)

    Is there a way to stop this happening? I would really appreciate your help.

    many thanks in advance

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: SaveAs and Kill filename

    If you want to check for the existence of a file you can use Dir.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    08-20-2012
    Location
    London,England
    MS-Off Ver
    Excel 2010
    Posts
    184

    Re: SaveAs and Kill filename

    Thanks, Norie.

    I'm not too sure how to do this. I have seen previous posts by you advising how to use Dir (furiously Googling before posting), but I have struggled to find the right answer.

    Could you possibly help me with a bit of the code? I just need the run-time error to disappear if the file is found, and to look for the other filename and kill if it is not found.

    TIA, once again.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: SaveAs and Kill filename

    Is it one of these two files you want to kill, but you aren't sure which?

    "XXXXX\" & Range("F41").Text & " " & Range("F11").Text & " -AFC" & ".xlsm"

    "XXXXX\" & Range("F41").Text & " " & Range("F11").Text & "-REJ -AFC" & ".xlsm"

    If it is then perhaps something like this.
    Please Login or Register  to view this content.
    PS You can replace Goto Quit with Exit Sub.

  5. #5
    Forum Contributor
    Join Date
    08-20-2012
    Location
    London,England
    MS-Off Ver
    Excel 2010
    Posts
    184

    Re: SaveAs and Kill filename

    That worked perfectly. Thanks.

    I just added the Dim strFile name.

    Thank you once again.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Complex SaveAs and Kill Macro Help
    By Sh0ck3d in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-18-2013, 08:22 PM
  2. saveas filename=inputbox value?
    By jazbath in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-01-2008, 07:26 PM
  3. Use VBA to change a filename while using SaveAs
    By BigBas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-14-2007, 01:55 AM
  4. VBA- SaveAs filename and add
    By Lucifix in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-21-2007, 06:09 AM
  5. FileName SaveAs
    By alanford in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2005, 10:48 AM

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