+ Reply to Thread
Results 1 to 8 of 8

File being over written

  1. #1
    Forum Contributor
    Join Date
    01-18-2012
    Location
    nr Salisbury, UK
    MS-Off Ver
    Excel 2010
    Posts
    126

    File being over written

    I am utterly baffled as to why a Word docx file is being overwritten when in one Workbook but not in another. The code is exactly the same in both, except for the file path to open the Workbook and its corresponding Word docx template. I have even gone to the extent of replacing the code in the offending Workbook with the code from the Workbook where it doesn’t happen (changing filepaths along the way)

    Silly question maybe but is there any settings in the offending Workbook that could be causing it; but got to the point that I am clutching at straws now.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: File being over written

    Do you generate a new file name for each Word doc save? If yes, perhaps the problem workbook isn't generating a new unique name for some reason. I cannot be more specific based on the limited info provided.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    01-18-2012
    Location
    nr Salisbury, UK
    MS-Off Ver
    Excel 2010
    Posts
    126

    Re: File being over written

    When the new Word.docx is first saved the filepath is self-created from Customer Name, Invoice#, Month and Year. My coding is such that if a later date you try and create it again you are messaged that it already exists and you have to click OK on the message dialog and you are taken back and given various options as what to do (do nothing, overwrite it or save with new name).


    Since first post I have been into both Excel and Word file settings & cleared the recent document history, deleted/created some relevant Customer folders, created a new template, changed filepaths in the code. (Had suspicions about the template)

    To my great relief everything is now running as it should.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: File being over written

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  5. #5
    Forum Contributor
    Join Date
    01-18-2012
    Location
    nr Salisbury, UK
    MS-Off Ver
    Excel 2010
    Posts
    126

    Re: File being over written

    Spoke to soon!! But I have narrowed it down to the changes I have made to the SaveAs2 command


    This version will do what I want and through up the ‘File Exists’ message if already exists, (Document title would be 'Haggas Inv#01 (January)2016' )

    Please Login or Register  to view this content.
    This is the revised version where I am trying to include the Inv# in the Filepath. But it will not give ‘File Exists’ message when the file does exist, it simply overwrites the file
    (Document title would be 'Haggas Inv# e???? (January)2016' )



    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    01-18-2012
    Location
    nr Salisbury, UK
    MS-Off Ver
    Excel 2010
    Posts
    126

    Re: File being over written

    I believe the problem was simply a matter of me NOT changing the strFilename path to match the changes in the SaveAs2 FileName path (See previous post)

    strFilename was this

    Please Login or Register  to view this content.
    Should have been this
    Please Login or Register  to view this content.
    Have run it umpteen times, seems OK
    Another case of not seeing the wood for the trees

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: File being over written

    Try this...
    Please Login or Register  to view this content.
    If that doesn't help, you could test if the file exists before saving
    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 02-08-2016 at 06:56 PM.

  8. #8
    Forum Contributor
    Join Date
    01-18-2012
    Location
    nr Salisbury, UK
    MS-Off Ver
    Excel 2010
    Posts
    126

    Re: File being over written

    What have been dealing with here is part of one Sub routine run from a userform that has 4 options, (Exit, Create Inv, Overwrite it, Save with new name) each Sub has routine to handle whether file exists or not depending on which option is selected. Set up in such a way that if it doesn’t exist it will create it, if it does exist a message dialog box tells you so and your taken back to the main routine where you can make the deliberate option to Overwrite it or Save with new name.

    You helped me with another aspect of this Sub routine here

    http://www.excelforum.com/excel-prog...ml#post4311244

    Not tried your solution as the Overwriting issue was resolve: (See previous post #6)

    But many thanks for your help.

+ 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. [SOLVED] pass the file name written in a cell to the file path
    By Megatronixs in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-26-2014, 07:54 AM
  2. Replies: 3
    Last Post: 05-21-2013, 08:22 AM
  3. encoding a text file written by VBA
    By duckboy1981 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-19-2009, 01:02 PM
  4. recovering over-written file
    By SRussell in forum Excel General
    Replies: 2
    Last Post: 07-05-2008, 01:41 PM
  5. Text File Written Event?
    By blueperfume300 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2007, 03:23 AM
  6. Startsector where file is written on
    By Jos Vens in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-10-2005, 07:10 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