+ Reply to Thread
Results 1 to 14 of 14

Code to save file

  1. #1
    Registered User
    Join Date
    11-14-2007
    Posts
    11

    Code to save file

    Hello, I am new to this forum and need some help.

    I have this code to save a worksheet into a specific directory:

    Please Login or Register  to view this content.
    Cells B9 and B7 give the name to the file.

    If the file already exists, I get a warning. If I click YES, it will overwrite the file, if I click NO, it will give me a run time error 1004.

    What I am looking for is a code that closed the warning when clicking on NO and does not give me the run time error.

    Thank you.
    Last edited by VBA Noob; 11-14-2007 at 02:42 PM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835
    try not to error out
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    11-14-2007
    Posts
    11

    Code to save file

    Thanks for your reply.

    Sorry but I am getting a error on line

    Please Login or Register  to view this content.
    Last edited by VBA Noob; 11-14-2007 at 02:41 PM.

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Jumpy

    Please read forum rules & wrap your VBA code

    A thread with the rules is available at the top of each forum or see links below

    If you do not understand the VBA code wrap instructions have a look at my last reply in this thread
    http://www.excelforum.com/showthread.php?t=583950
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  5. #5
    Registered User
    Join Date
    11-14-2007
    Posts
    11

    Code to save file

    Sorry. This is the part of code that does not work. Appreciate your help.

    Please Login or Register  to view this content.
    Thanks.

  6. #6
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Try this

    Please Login or Register  to view this content.

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Are you using Excel 2007?
    Hope that helps.

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

    Free DataBaseForm example

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835
    Quote Originally Posted by Jumpy
    Sorry. This is the part of code that does not work. Appreciate your help.

    Please Login or Register  to view this content.
    Thanks.
    Sorry missed " at the end
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-14-2007
    Posts
    11

    Code to save file

    Thank you. This works better but still need some help.

    The following code informs me that a file with that name already exists.

    Please Login or Register  to view this content.
    I need to add two more buttons on the warnings.
    One asking if you want to replace the existing file.
    The other, NO, abort the command.

    Thank you.

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835
    try
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    11-14-2007
    Posts
    11

    Code to save file

    Thank you. Still a problem.
    Please see how I have changed the code:

    Please Login or Register  to view this content.
    When I click on the button, even if a file with name similar to cells B9 and B6 does not exists, I get the message, Is Already Exists.
    Obviously, if a file is not present in the above directory, it should save it automatically.

    Last issue. Is there the change to add another cell range to the aboe FILE NAME criteria? Example, I want to add B1?

    Thank you.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835
    try change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    11-14-2007
    Posts
    11

    Code to save file

    Sorry but cannot get it to work. I am not very familiary with VBA but I will try to go over the code so that you can better understand what I am trying to achieve:

    1) I need a cmdbutton on a worksheet to save the workbook as an excel file in a specific directory. In this directory files are named by First and Last Name. In my worksheet the range of cells which are used to give this data is B9 and B7. The code will verify if a file with a similar name exists. If YES, I need a message asking if to replace. If not, a need a NO button to abort and go back to the worksheet.

    Let's now check the code:

    Please Login or Register  to view this content.

    Thank you for your patiente.

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835
    Sorry I need to go off-lline now

    I'll be busy tomorrow, so I will look at it on Sat here.

+ 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