+ Reply to Thread
Results 1 to 5 of 5

Stop overwrite of file if it already exists, no popup wanted

  1. #1
    Forum Contributor
    Join Date
    09-14-2012
    Location
    Tucson, Arizona, USA
    MS-Off Ver
    Office 2010
    Posts
    105

    Stop overwrite of file if it already exists, no popup wanted

    I can get rid of the popup/warning about overwriting an existing file, but I just can't figure out how to get the macro NOT to overwrite the file if it already exists. A coworker ended up deleting a couple days worth of data entry the beginning of this month, so it was no big deal at that time (barely an hours worth of work this time), but I want to prevent a complete loss of the month if they decide to do it again later.

    I've included the entire code below, but have highlighted the coding I'm working with in red below. So long as I leave out the red coding, the popup comes up, but nobody reads it, so the file gets overwritten

    Thanks in advance for your help

    Please Login or Register  to view this content.
    Last edited by LoneWolf3574; 12-06-2012 at 03:01 AM.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Stop overwrite of file if it already exists, no popup wanted

    Hi, LoneWolf3574,

    have you tried using Dir and deciding on the length of the string prior to saving if to or not save?

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor
    Join Date
    09-14-2012
    Location
    Tucson, Arizona, USA
    MS-Off Ver
    Office 2010
    Posts
    105

    Re: Stop overwrite of file if it already exists, no popup wanted

    I'm sorry, I don't understand what you are asking Holger. I'm still learning VBA and rate myself as noobie still.

    What I would like is for the coding to automatically select no for the overwrite warning and leave the already present file unchanged.

    Also, I found with more searching that I left some necessary coding out turning the warnings back on. So I've added the Application.DisplayAlerts = True code after the next line per what I have found.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Stop overwrite of file if it already exists, no popup wanted

    Hi, LoneWolf3574,

    in your code you use
    Please Login or Register  to view this content.
    What I meant was to wrap this one line of code in an If-Statement and only save if no workbook with that name is present like
    Please Login or Register  to view this content.
    which may lead to the following code also being dragged into the If-Statement.

    And you could cut down
    Please Login or Register  to view this content.
    to either
    Please Login or Register  to view this content.
    or even shorter to
    Please Login or Register  to view this content.
    Ciao,
    Holger

  5. #5
    Forum Contributor
    Join Date
    09-14-2012
    Location
    Tucson, Arizona, USA
    MS-Off Ver
    Office 2010
    Posts
    105

    Re: Stop overwrite of file if it already exists, no popup wanted

    Holger, you are a godsend. That worked perfectly, I've been trying to figure this out for days before I decided to ask for help.

+ 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