+ Reply to Thread
Results 1 to 22 of 22

Copy a sheet into a new book and save file name as the current date.

  1. #1
    Registered User
    Join Date
    11-11-2004
    Posts
    57

    Talking Copy a sheet into a new book and save file name as the current date.

    Can anyone help with this?

    I have an excel file which I use when I book keep journals in work. Each time I come across a new piece of bookkeeping I add to the file, name the sheet and index it. (I've attached a loose example for illustration) so the bookkeeping template.xls gets bigger every day.

    Currently, when I book keep on a particular day, I open the template.xls workbook;

    draft my journals;

    and then manually copy the worksheets I have completed during the day from the template.xls workbook and paste the sheets into a new book and save the days bookkeeping as the current date.


    With the file I have attached can someone show me how to write a macro and apply it to each of the buttons on the various work sheet tabs (each button will run the same macro).

    Upon clicking a button, I would like the macro to;

    Copy the active sheet into a new book and save the file as the current date.

    Each subsequent click of a button the macro will check if the .xls file exists for the current date, if it does, then it will just copy the active worksheet to the file that has already been created.

    In the new file which is saved as the current date, I need to remove the macro button and the hyperlink that reads back to index.

    I have had some helpful macro's provided from another forum, however, the other forum does not appear to enable users to upload files, so I can't quite convey what it is I am trying to achieve.

    I'd be for any help.
    Thanks,
    Jay3
    Attached Files Attached Files

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copy a sheet into a new book and save file name as the current date.

    Hello Jay3,

    This macro has been attached to the buttons on all the worksheets. This will save the active sheet in your default directory on your main drive, usually C:\My Documents. You can change the path where the files are to be saved.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    11-11-2004
    Posts
    57

    Re: Copy a sheet into a new book and save file name as the current date.

    Thanks for this!

    My computer doesn't seem to like the 2nd line of the code?

    Please Login or Register  to view this content.

    Is it because I'm working on a Mac?

  4. #4
    Registered User
    Join Date
    11-11-2004
    Posts
    57

    Re: Copy a sheet into a new book and save file name as the current date.

    I can't get this Macro to work? Can anyone help me with it?
    Thank you!

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copy a sheet into a new book and save file name as the current date.

    Hello Jay#,

    I just got back in. Yes, you are right about that line of code. The Environ statement is not available to MAC users. You will need remove those statements and include the path to the folder where the file will be saved. I have never used the Kill statement on the MAC, so hopefully that won't be a problem.

  6. #6
    Registered User
    Join Date
    11-11-2004
    Posts
    57

    Re: Copy a sheet into a new book and save file name as the current date.

    Hi there,

    I'm now using your code in Excel 97 with Windows Vista, and it doesn't seem to like it either?

    Is it because of the version?

    Thanks

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copy a sheet into a new book and save file name as the current date.

    Hello Jay3,

    I don't have VIsta, for many reasons, but backward compatibility is not one of Vista's strengths. This was the first operating system to break with backward compatibility. The code should run in Excel '97. Here is a macro that will show you all the environmental variables on your system. Providing of course, Vista doesn't reject this as well. Copy this into a separate VBA module and run the macro ShowEnvironmentStrings. This will let you know if the environmental strings "homedrive" or "homepath" exist.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-11-2004
    Posts
    57

    Talking Re: Copy a sheet into a new book and save file name as the current date.

    Thanks, but I've got that line to work now but it falls over at activesheet.copy.

    This is the code I now have.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-11-2004
    Posts
    57

    Talking Re: Copy a sheet into a new book and save file name as the current date.

    This actually sort of works now, but there's a couple of things.

    When I click the button one it creats the worksheet and saves, then closes it as the current date.

    I actually want to click the buttons as and when I complete each journal,

    So I need the workbook to stay open and I would need code to tell the macro to check if the workbook (saved as the current date) actually exists.

    If it does exist then subsequent clicks of the macro button should just copy the active sheet into the newly created book.

    The current macro tries to overwrite the file on subsequent clicks and then falls over.

    Any suggestions?

    Thanks

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copy a sheet into a new book and save file name as the current date.

    Hello Jay3,

    Let's go back to the problem with the error. What is happening now and on which system?

  11. #11
    Registered User
    Join Date
    11-11-2004
    Posts
    57

    Talking Re: Copy a sheet into a new book and save file name as the current date.

    Hello,

    There are no errors now based on this code;

    Please Login or Register  to view this content.

    However, the macro needs to be amended as it's not quite what I need.

    I need the code to be modified to do the following;

    When the macro is executed for the first time (i.e. the first click of the button)
    Check if the workbook for the current day has been created, and if it hasn't create it and save it. (That works fine, however, can we leave the new workbook open as opposed to closing it?)

    On subsequent clicks of the button.The macro needs to copy and additional journals completed that day to the workbook which has already been saved, as opposed to trying to overwrite the existing file.

    In any given day I will use the "Workbook Template.xls" workbook to produce 10 or more journals, so I want to be able to click the save button as I go.

    I'd imagine the Macro will also need to check to the workbook which it creats is still open and if not open it prior to copying a worksheet accross.

    I do not need the macro to close the new workbook each time.

    Does this make sense?

    Thanks for your help.
    Jay

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copy a sheet into a new book and save file name as the current date.

    Hello Jay3,

    Here is the revised macro. This runs fine in Excel 2003. Try it out on your side and let me know what happens. Copy this code over the existing macro in your project.
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    11-11-2004
    Posts
    57

    Thumbs up Re: Copy a sheet into a new book and save file name as the current date.

    Fantastic!!!!

    Thanks very much for your help it works perfectly!

    Thank you!

  14. #14
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copy a sheet into a new book and save file name as the current date.

    Hello Jay3,

    Glad to know all is well. If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  15. #15
    Registered User
    Join Date
    11-11-2004
    Posts
    57

    Talking Re: Copy a sheet into a new book and save file name as the current date.

    Oh....one last thing.

    This is the path I need to save my bookkeeping to

    Please Login or Register  to view this content.
    Can you tell me what line I need to change in this code to do this?

    Please Login or Register  to view this content.

    Thanks again,
    John

  16. #16
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copy a sheet into a new book and save file name as the current date.

    Hello John,

    You need to combine the path with the file name.
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    11-11-2004
    Posts
    57

    Talking Re: Copy a sheet into a new book and save file name as the current date.

    Hi Leith,

    Apologies I didn't see that the thread has now gone onto a second page.

    I've made the amendment you mentioned and it save to the correct location, however, subsequent clicks of the macro button now cause excel to want to reopen the file (saved as todays date) and the macro doen't perform as did.

    Excel flashes up a message to say, the file is already open and reopening etc etc....

    Any suggestions.

  18. #18
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copy a sheet into a new book and save file name as the current date.

    Hello John,

    Obviously I am not fully awake. The path is wrong in the last post. Not that would cause the problem your having. In my tests of the macro, the second workbook stayed open and could be changed with no errors.

    Corrected File Path
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    11-11-2004
    Posts
    57

    Re: Copy a sheet into a new book and save file name as the current date.

    Hi Leith,

    I spotted the filename .xls bit and omitted it, however, I'm still getting this problem?

    I'm on excel 97, could that be why?

    Thanks,
    John

    This is the code now, tell me if I've inserted it in the wrong place.

    PS - I also set Filepath as string, not sure if this is correct?

    Please Login or Register  to view this content.

  20. #20
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copy a sheet into a new book and save file name as the current date.

    Hello John,

    The code looks fine. Can you email a copy of your workbook to run on my system? My email is LeithRoss@gmail.com

  21. #21
    Registered User
    Join Date
    11-11-2004
    Posts
    57

    Re: Copy a sheet into a new book and save file name as the current date.

    Hi Leith,

    Can't email, but I've attached a template.

    Thanks
    Attached Files Attached Files

  22. #22
    Registered User
    Join Date
    11-11-2004
    Posts
    57

    Re: Copy a sheet into a new book and save file name as the current date.

    Hi Leith,

    Any joy with this?

    Thanks
    John

+ 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