+ Reply to Thread
Results 1 to 4 of 4

Macro to save file - save name from cell containing a date using different date formatting

  1. #1
    Registered User
    Join Date
    02-05-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    14

    Macro to save file - save name from cell containing a date using different date formatting

    Hi there,

    I am trying to create a macro to run from a form button, within a report, to save a file to a variable file path and name depending on the date value in cell B5.

    The format of B5 looks like - 13/08/2014 16:39

    The file path has folders for each year in format "yyyy" with each year having sub folders for each month in format "mm".

    The file name is just the date only and is formatted "dd.mm.yy" e.g. 13.08.14

    I have tried the code below in various permutations but always end up with an error - Method 'SaveAs' of object '_Workbook' failed. After extensive searching for the answer I have decided to ask for help.

    Please Login or Register  to view this content.
    Can anyone please assist?

    Many thanks,
    d_max_c

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Macro to save file - save name from cell containing a date using different date format

    Just tried it and it works. I took the date out b5, and it didnt, double check that you are using the right worksheet, by prefixing range("b5") with Worksheets("relevantsheet").range("b5").vlaue

    and i'd probably do a <>"" and isdate() check on it to.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Registered User
    Join Date
    02-05-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Macro to save file - save name from cell containing a date using different date format

    Thank you for the reply nathansav but it's still not working for me. I have changed the code to read:

    dtDate = Worksheets("Master").Range("B5").Value

    B5 is definately the source cell but still get the error message. I have noticed however, that with the error message, the active work sheet name changes to the save name rather than saving the file.

    I'm not sure how I should apply <>"" and isdate() check either.

  4. #4
    Registered User
    Join Date
    02-05-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Macro to save file - save name from cell containing a date using different date format

    Hi nathansav, thanks again, you were right. I got it to work now. I didn't check the file path properly and have amended some folder names to correspond with the code.

    However, sheet 'Master' is still being renamed the same as the save name - 13.08.14

    I would like to preserve the workbook as is is if possible. Is there anything I can do to prevent this sheet rename?

    Many thanks.

+ 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] save open worksheet to file and include date of save
    By shaz0503 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-12-2014, 08:50 AM
  2. [SOLVED] Macro to Save File to Location Folder Based on Date in Cell
    By John_Day83 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-03-2013, 05:34 PM
  3. [SOLVED] VBA to save file as name of tab & date in cell
    By kenadams378 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-28-2013, 06:31 AM
  4. [SOLVED] Macro to Save As a file with a date in dd-monthname-yyyy
    By witcomm in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-21-2013, 02:20 AM
  5. Conditional formatting based on the file save date
    By rpadilla65 in forum Excel General
    Replies: 3
    Last Post: 10-28-2011, 08:05 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