+ Reply to Thread
Results 1 to 33 of 33

Save copy of workbook with date in specific location and exit

  1. #1
    Forum Contributor
    Join Date
    05-12-2021
    Location
    USA
    MS-Off Ver
    Microsoft Office LTSC Professional Plus 2021
    Posts
    212

    Save copy of workbook with date in specific location and exit

    Hello, I am wondering if it would be possible via VBA to save a copy of a daily attendance sheet to a specific shared folder with the date in the file name. So right now, the sheets are named something like this:

    010221 Grocery & Dairy 1st Shift ABSENTEE BLANK (1ST SHIFT).xlsm

    and and even though this is not the shared drive, this is just a test folder I created which I will change the pathway to the shared one.

    C:\Users\bhar05h\Desktop\attendance sheets\1st Shift Grocery&Dairy

    Would something like that be possible? To have a fixed file name with a changing date save somewhere specific at the click of a macro-assigned button?

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Save copy of workbook with date in specific location and exit

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    05-12-2021
    Location
    USA
    MS-Off Ver
    Microsoft Office LTSC Professional Plus 2021
    Posts
    212

    Re: Save copy of workbook with date in specific location and exit

    Hi Logit, thanks for this. The edits I would have to make, would they make the macro look like this?

    Sub savesheet()
    Dim Name As String
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    ActiveSheet.Copy

    Name = Environ("UserProfile") & "C:\Users\bhar05h\Desktop\attendance sheets\1st Shift Grocery&Dairy" & ActiveSheet.Name & " " & _
    Format(Now(), "mm.dd.yy") & ".xlsm"

    ActiveSheet.SaveAs Filename:=Name, FileFormat:=52
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    ActiveWorkbook.Close
    End Sub

    Or would there be something else I am needing to do to put it to my specifications? My apologies as I am not at all familiar with the language contained in VBA to know what to edit.
    Last edited by PitchNinja; 05-27-2021 at 03:10 PM.

  4. #4
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Save copy of workbook with date in specific location and exit

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-02-2017
    Location
    Huntsville, Alabama
    MS-Off Ver
    2010
    Posts
    57

    Re: Save copy of workbook with date in specific location and exit

    @PitchNinja,

    You end up with a lot of files with the scenario you described. I'd suggest putting a macro-enabled workbook into a specific directory, a subdirectory named Grocery & Dairy or Grocery & Dairy 1st Shift, a file within that subdirectory named Grocery & Dairy 1st Shift ABSENTEE BLANK (1ST SHIFT), and your template should ask the date (with a default of current date), and save when told - to a new sheet with the sheet name being the date, on that workbook in the subdirectory.

    In that way, if something hangs you have opportunity for backups to only deal with two files, plus easy additional newly saved logs if you decide to expand the recordkeeping. This way it's also easy to implement without macros just copying over sheets on two workbooks while you edit/write code to make additional features/changes over time...

    I find doing most of the structure planning up front helps later on.

    Sorry can't help with the coding (just ramping up a new project), but I hope this helps.

    GC

  6. #6
    Forum Contributor
    Join Date
    05-12-2021
    Location
    USA
    MS-Off Ver
    Microsoft Office LTSC Professional Plus 2021
    Posts
    212

    Re: Save copy of workbook with date in specific location and exit

    Thanks for the responses. I do have some questions. I attached a picture of what I am getting when I run the macro.Attachment 734490

    As you see, it actually saved it outside of the intended folder. Also the name is kind of off: 1st Shift Grocery&DairyGROCERY 05.28.21
    If it could just read 1st Shift Grocery&Dairy 05.28.21

    Just making a guess, but would that be something as simple as altering the VBA code from:

    Name = Environ("UserProfile") & "\Desktop\attendance sheets\1st Shift Grocery&Dairy" & ActiveSheet.Name & " " & _
    Format(Now(), "mm.dd.yy") & ".xlsm"


    To this:

    Name = Environ("UserProfile") & "\Desktop\attendance sheets\1st Shift Grocery&Dairy" & " " & _
    Format(Now(), "mm.dd.yy") & ".xlsm"

    Could it somhow be changed so that the date is before the 1st shift grocery name?

    Also, Grug.Crood, I'm trying to follow what you're saying but I'm not clear. If it helps any, this folder will be named current fiscal year, the live version of this. When the fiscal year is up, the files would be moved to a 21 Fiscal folder or something of the like.
    Last edited by PitchNinja; 05-28-2021 at 08:22 AM.

  7. #7
    Registered User
    Join Date
    10-02-2017
    Location
    Huntsville, Alabama
    MS-Off Ver
    2010
    Posts
    57

    Re: Save copy of workbook with date in specific location and exit

    Quote Originally Posted by PitchNinja View Post
    Also, Grug.Crood, I'm trying to follow what you're saying but I'm not clear. If it helps any, this folder will be named current fiscal year, the live version of this. When the fiscal year is up, the files would be moved to a 21 Fiscal folder or something of the like.
    @PitchNinja,

    I reckon what I was hinting at is by having a structure hierarchy for each "level" of data you gain a system that can be expanded and easily parsed/accessed.

    So this (my suggestion)

    (dir) Grocery & Dairy 1st Shift
    (subdir) 1st Shift ABSENTEE
    main template workbook (can have a shortcut on your desktop...)
    [INDENT]
    (subdir)Data (where you copy files or add sheets to workbooks)
    [/[INDENT][INDENT]
    Your workbook with multiple dated sheets
    [/[INDENT]

    So if my suggestion of trading multiple files (workbooks) for one workbook with multiple dated sheets is not so good because it has 365 sheets, you can just add a subdirectory for, say months and have 28/31 sheets per workbook, or weeks (Julian calendar) with seven sheets per workbook, etc.

    It's just how I might organize, everybody is different ... so what I really mean, is just consider how you plan to access things before implementation. For me, I just noticed that directories with hundreds of files can be problematic.

    However you decide to organize, I'm betting the coding changes from one method to the next only amount to minor coding changes...

    GC

  8. #8
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Save copy of workbook with date in specific location and exit

    Just making a guess, but would that be something as simple as altering the VBA code from
    Yes .. change that portion as you indicated. Keep in mind that anytime you run this macro, the name of the file
    will always be the same except for the date.

  9. #9
    Forum Contributor
    Join Date
    05-12-2021
    Location
    USA
    MS-Off Ver
    Microsoft Office LTSC Professional Plus 2021
    Posts
    212

    Re: Save copy of workbook with date in specific location and exit

    Quote Originally Posted by Logit View Post
    Yes .. change that portion as you indicated. Keep in mind that anytime you run this macro, the name of the file
    will always be the same except for the date.
    Hi Logit, sorry I never got a notification of your latest response and I've been so busy I haven't had time until now to revisit this, but I did change the coding and it did eliminate the grocery name duplication. However, it is not saving the file in the actual folder I want it to go into.

    The macro is saving the file to:
    C:\Users\bhar05h\Desktop\attendance sheets

    and I was wanting to save it to:

    C:\Users\bhar05h\Desktop\attendance sheets\1st Shift Grocery&Dairy

    I do see in the coding that that is what you had, but I am not sure why it's not putting it there.

    Also, could you tell me what the coding would be to have the file save the name in this format: 05.28.21 1st Shift Grocery&Dairy
    That is just reversing the positions of the date. I thought I could do it myself in the coding but everything I tried messed it up so I guess I don't know what to cut out and re-paste.
    Last edited by PitchNinja; 06-08-2021 at 09:04 AM.

  10. #10
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Save copy of workbook with date in specific location and exit

    The following macro saves the sheet as indicated, on my machine :

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    05-12-2021
    Location
    USA
    MS-Off Ver
    Microsoft Office LTSC Professional Plus 2021
    Posts
    212

    Re: Save copy of workbook with date in specific location and exit

    Thanks. It is saving it to the correct folder now. I did have to tweak the name somewhat to get the date to appear first but ultimately got what I wanted here so thank you very much for your help!

    Grug.Crood, I will take your suggestion into consideration as it does seem like a solid idea. In the end, it isn't me who is making the decision regarding that but I at least wanted to try and keep this as close as possible to the format they currently have them in.
    Last edited by PitchNinja; 06-08-2021 at 12:40 PM.

  12. #12
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Save copy of workbook with date in specific location and exit

    Glad to help ! Cheers.

  13. #13
    Forum Contributor
    Join Date
    05-12-2021
    Location
    USA
    MS-Off Ver
    Microsoft Office LTSC Professional Plus 2021
    Posts
    212

    Re: Save copy of workbook with date in specific location and exit

    Quote Originally Posted by Logit View Post
    Glad to help ! Cheers.
    Actually one more question. I did show the supervision how it works and they do like it, but they are asking me if it is at all possible to have it automatically send the file as an email to a few specific people. Is that something that is doable do you know?

  14. #14
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Save copy of workbook with date in specific location and exit

    Always the same people ?
    Always the entire workbook that is being saved ?

  15. #15
    Forum Contributor
    Join Date
    05-12-2021
    Location
    USA
    MS-Off Ver
    Microsoft Office LTSC Professional Plus 2021
    Posts
    212

    Re: Save copy of workbook with date in specific location and exit

    Yes, I believe it is the same 3 or 4 people and it would also be the entire workbook that is emailed. Thinking further on this, sometimes the supervisors do have to email revisions of the attendance sheets out that they've already sent. In light of that, it might be better to even just have it bring up the outlook message with the attachment automatically in there as well as the people to send the email to so that all they'd really need to do is edit the subject line to change the date(unless the date change could also be done automatically in the subject line?) and also edit the body to say whatever they want like "revision to 1st shift sheet" or something along those lines.

    Basically, it's a few managers that would want this emailed in case they are out of office and all they have is their phones to check the sheets, at least they could do so from their phones and then make whatever contact with whomever they need to about specific items on the sheet.

    If it might even be better/easier, I could propose to them the idea of creating a separate "management email group" (right now there is only one for supervisors, and sometimes managers include themselves in that group and sometimes not) if that would create less of a hassle in the actual coding.

    If it IS possible, could that also go inside with the same macro that saves the file?

    Hope that clarifies

  16. #16
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Save copy of workbook with date in specific location and exit

    Give me a little time to review.

  17. #17
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Save copy of workbook with date in specific location and exit

    .
    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    05-12-2021
    Location
    USA
    MS-Off Ver
    Microsoft Office LTSC Professional Plus 2021
    Posts
    212

    Re: Save copy of workbook with date in specific location and exit

    Thank you so much Logit. I didn't get a notification again of your updated post, but happened to check to post another question regarding it here. This updated solution will absolutely work perfectly for what I need! I do have a question regarding the email portion of the code you gave, as I can see that would be handy to be able to just email files too not necessarily save and rename and such.

    I tried using it on a file I use regularly and have to email not as often, but I altered it to the specifications of that file and came out with this code:

    Please Login or Register  to view this content.
    My question is, is there a simple way to alter this code to email just one tab of the workbook like the tab you're currently on or would you have to specify its name? Would it be this specific line of coding that would need changed:

    .Attachments.Add Application.ActiveWorkbook.FullName

    or would it be more involved than that?

    Thanks again so very much for your help!

  19. #19
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Save copy of workbook with date in specific location and exit

    .
    This modified macro will attach the ACTIVE SHEET and email.

    Please Login or Register  to view this content.

  20. #20
    Forum Contributor
    Join Date
    05-12-2021
    Location
    USA
    MS-Off Ver
    Microsoft Office LTSC Professional Plus 2021
    Posts
    212

    Re: Save copy of workbook with date in specific location and exit

    I've altered the coding as needed to fit very specific needs and it is working as I want it to. These all will surely come in handy. Thank you very much again for all your help in this!

  21. #21
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Save copy of workbook with date in specific location and exit

    Glad to help.

  22. #22
    Forum Contributor
    Join Date
    05-12-2021
    Location
    USA
    MS-Off Ver
    Microsoft Office LTSC Professional Plus 2021
    Posts
    212

    Re: Save copy of workbook with date in specific location and exit

    Okay, so I presented this to those in charge and they really liked the idea and want to get it rolling. I always have to test these things on my desktop first though so I don't go messing up something in the actual location. It worked just fine on my desktop when I created the folders and sub-folders and I showed it to them and they could see it did so they gave me the go ahead to do it for the actual location this will all happen in which is NOT my desktop, it is on the network drive. I figured no problem, all I will need to do is change the file pathway. I decided to start with the 1st Shift Perishable sheet, so I ended up with this:

    Please Login or Register  to view this content.
    It did compose the email but I can't find the file in the location pathway I specified in the VBA code. I had copied and pasted the file path over the existing path that was on my desktop that was working. I guess my question then is, does this not work in the case of folders being on network drives?
    Last edited by PitchNinja; 06-24-2021 at 09:48 AM.

  23. #23
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Save copy of workbook with date in specific location and exit

    PitchNinja

    There is a difference between a desktop computer and accessing Net Work locations. Regretfully I am not familiar with the Net Work environment.

    Would someone else on the Forum please assist PitchNinja with this need ?




    (ps: PitchNinja ... you may need to mark this thread SOLVED. Then repost with the final macro in your post (reference back to this URL as well in your message) requesting assistance with
    the Net Work Environment. Suggest a title for your new post similar to : Macro Works On Desktop But Not On Net Work Environment. I will attempt to follow your progress as I am
    interested in learning the differences.)

  24. #24
    Forum Contributor
    Join Date
    05-12-2021
    Location
    USA
    MS-Off Ver
    Microsoft Office LTSC Professional Plus 2021
    Posts
    212

    Re: Save copy of workbook with date in specific location and exit

    No worries, thank you for all your help, it is at least usable for the files I DO have on desktop. I will create a new thread.

  25. #25
    Forum Contributor
    Join Date
    05-12-2021
    Location
    USA
    MS-Off Ver
    Microsoft Office LTSC Professional Plus 2021
    Posts
    212

    Re: Save copy of workbook with date in specific location and exit

    Hi Logit, so I ran into an issue I can't believe I hadn't even noticed. It is only automatically saving one tab in this file and I actually need it to save the whole workbook. When it attaches it, it is doing it correctly, it's just when it is saving it that needs fixed. This code below is for saving to network option but I figured we're just changing a portion of the code for saving the file and don't need to bother with pathways and such? I don't have really any knowledge of coding. I tried it myself thinking maybe I could just change ActiveSheet to ActiveWorkbook but that didn't work. (worth a shot)

    Please Login or Register  to view this content.
    Can you advise on what would need changed?
    Last edited by PitchNinja; 06-24-2021 at 09:54 AM.

  26. #26
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Save copy of workbook with date in specific location and exit

    On my desktop computer, the line you are using works here :


    Please Login or Register  to view this content.
    If it isn't working there, I'm guessing it is due to the network environment, of which I am not familiar.

  27. #27
    Forum Contributor
    Join Date
    05-12-2021
    Location
    USA
    MS-Off Ver
    Microsoft Office LTSC Professional Plus 2021
    Posts
    212

    Re: Save copy of workbook with date in specific location and exit

    Quote Originally Posted by Logit View Post
    On my desktop computer, the line you are using works here :


    Please Login or Register  to view this content.
    If it isn't working there, I'm guessing it is due to the network environment, of which I am not familiar.
    Is that the email portion though? That was working fine for me - It was the Saving to location issue. I was actually finding that even on the desktop it was only saving the one tab and not the whole workbook.

  28. #28
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Save copy of workbook with date in specific location and exit

    I misunderstood ...

    Try this resource : https://docs.microsoft.com/en-us/off...-network-drive

  29. #29
    Forum Contributor
    Join Date
    05-12-2021
    Location
    USA
    MS-Off Ver
    Microsoft Office LTSC Professional Plus 2021
    Posts
    212

    Re: Save copy of workbook with date in specific location and exit

    Quote Originally Posted by Logit View Post
    .
    Please Login or Register  to view this content.
    If we go back to this post which is the one you have for saving the file to the desktop, is it something in this portion of the code that would save all tabs and not just one:

    Please Login or Register  to view this content.
    Would it be a small change to the code? I tried doing something like this with the underlined being what I changed:

    Please Login or Register  to view this content.
    That's ultimately what I'm looking to change, not save just the one tab, but the whole file. If I can get it to work on the desktop test copy, I should be able to get it to work on the network. I'm just not sure what the coding change is from Sheet to workbook. I hope that might clarify?

  30. #30
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Save copy of workbook with date in specific location and exit

    You shouldn't need the "ActiveWorkbook.Copy" ... nor

    Please Login or Register  to view this content.
    Try it without those items

  31. #31
    Forum Contributor
    Join Date
    05-12-2021
    Location
    USA
    MS-Off Ver
    Microsoft Office LTSC Professional Plus 2021
    Posts
    212

    Re: Save copy of workbook with date in specific location and exit

    Quote Originally Posted by Logit View Post
    You shouldn't need the "ActiveWorkbook.Copy" ... nor

    Please Login or Register  to view this content.
    Try it without those items
    Okay so that is now including all tabs which is great. Basically this file comes from a template called Absentee Blank(3rd Shift). When the macro is run, it is renames that template to the specific dated name in the folder. After I execute the macro, I noticed it closes the "template copy" and only leaves open the new specific dated copy. It doesn't save changes to the template copy. I'm just thinking it would probably be good to have it also just simply save the template as well just in case there needs to be any revisions to it and they can resend. Is it a simple thing to add that? I think that was what it was doing with the Active.Sheet copy code line maybe?
    Last edited by PitchNinja; 06-24-2021 at 11:16 AM.

  32. #32
    Forum Contributor
    Join Date
    05-12-2021
    Location
    USA
    MS-Off Ver
    Microsoft Office LTSC Professional Plus 2021
    Posts
    212

    Re: Save copy of workbook with date in specific location and exit

    EDIT: I found it. I had to add "ActiveWorkbook.Save" in place of where I had ActiveWorkbook.copy.

    Thank you once again for steering me on that, Logit.

  33. #33
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Save copy of workbook with date in specific location and exit

    Glad you worked it out.

    Cheers.

+ 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] Copy Specific Worksheet into a new workbook and save it in user prompted file location
    By subbby in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-11-2020, 05:44 PM
  2. Need to save a copy of a workbook to another location
    By aliciaward1001 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-27-2018, 03:57 PM
  3. Save Backup File to Different Location On Save and Exit
    By slindfors in forum Excel General
    Replies: 0
    Last Post: 06-16-2015, 09:01 AM
  4. [SOLVED] Trying to save workbook to a specific location - 1004 error
    By wazimu13 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-25-2013, 03:19 PM
  5. Replies: 9
    Last Post: 06-24-2013, 04:14 PM
  6. Save Backup copy on Workbook Exit
    By Foreverlearning in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-29-2012, 06:38 PM
  7. macro to save workbook with specific type and location
    By wolfm in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-24-2011, 02:36 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