+ Reply to Thread
Results 1 to 16 of 16

Name file depending on the week's number

  1. #1
    Registered User
    Join Date
    11-21-2015
    Location
    france
    MS-Off Ver
    2010
    Posts
    57

    Name file depending on the week's number

    Hello everyone,

    I have this macro hereunder with a workbook with the number of the current week in it ( name "wk49production" for the week 49)
    But of course I wouldn't like to change the number of the week every week. Is there a way for excel to change automatically the workbook name depending on the current week?

    Please Login or Register  to view this content.

    Thank you very much in advance.

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Name file depending on the week's number

    If the file to use is always present you could use
    Please Login or Register  to view this content.
    - Battle without fear gives no glory - Just try

  3. #3
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Name file depending on the week's number

    I recently did something similar.
    Please Login or Register  to view this content.
    ...I didn't compile it and there may be a better way to do it, but let me know if you have any issues
    Last edited by joe31623; 12-05-2015 at 01:46 PM.

  4. #4
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Name file depending on the week's number

    ...looks like someone else came up w/ a better solution, but if the above implementation is useful (now that I see you want week number over the year), I would loop from 1/1/YYYY to now() and increment WeekNumber using DateDiff("d", #1/1/YYYY#, Now()) mod 7 function as the limit to the For loop.

  5. #5
    Registered User
    Join Date
    11-21-2015
    Location
    france
    MS-Off Ver
    2010
    Posts
    57

    Re: Name file depending on the week's number

    Thank you very much to all of you for your help.

    I tried this one from PCI, but I don't get why I get an error message (on the set db line).


    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Name file depending on the week's number

    Does the file named WkStg & "production" exist ???
    You could use next code and see how variable WkStg show the full file name

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-21-2015
    Location
    france
    MS-Off Ver
    2010
    Posts
    57

    Re: Name file depending on the week's number

    My file is named "Wk49Production"...as we are this week, week 49, I assume it should be working so don't see why not. Message error saying it is not part of the selection

  8. #8
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Name file depending on the week's number

    Houps ....!
    Try next code
    Please Login or Register  to view this content.
    Check if WkStg has the right value = filename with extension
    Last edited by PCI; 12-06-2015 at 03:29 PM. Reason: Code tags misssing

  9. #9
    Registered User
    Join Date
    11-21-2015
    Location
    france
    MS-Off Ver
    2010
    Posts
    57

    Re: Name file depending on the week's number

    Thank you so much for your help PCI. I have just checked. And indeed the error comes from the fact that Wkstg gets the value 50..instead of 49 (as current week is 49).
    Any idea why?

  10. #10
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Name file depending on the week's number

    WEEKNUM(NOW(),2)
    2--> week begins on Monday
    Ben Van Johnson

  11. #11
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Name file depending on the week's number

    Ah la la...!
    The week number is a curious story:
    How do you know that the week number is 50 ?
    Are you using the ISO week number or other one ?
    Just to give some hits:
    The first week of the year is the one with the more days of the new year in the week: 4 days
    The number of days in the week is counted from the first to the last day of the week
    What is the first day of the week: Sunday or Monday ?
    See next code
    Please Login or Register  to view this content.
    Last edited by PCI; 12-06-2015 at 05:09 PM.

  12. #12
    Registered User
    Join Date
    11-21-2015
    Location
    france
    MS-Off Ver
    2010
    Posts
    57

    Re: Name file depending on the week's number

    Thank you so much. Learning a lot from you, thanks !

  13. #13
    Registered User
    Join Date
    11-21-2015
    Location
    france
    MS-Off Ver
    2010
    Posts
    57

    Re: Name file depending on the week's number

    Quick question:

    I'd like the name to look like "Wk 49 Production schedule 151206".
    With the code hereunder I have "Wk 49 Production schedule 15126".

    How can I deal with the "0"?

    Please Login or Register  to view this content.
    Last edited by ced0802; 12-06-2015 at 07:24 PM.

  14. #14
    Registered User
    Join Date
    11-21-2015
    Location
    france
    MS-Off Ver
    2010
    Posts
    57

    Re: Name file depending on the week's number

    Sorry I found it


    I post it if it can help someone someday :
    Please Login or Register  to view this content.

  15. #15
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Name file depending on the week's number

    Maybe:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  16. #16
    Registered User
    Join Date
    10-24-2012
    Location
    Thailand
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Name file depending on the week's number

    here is function for ISO weeks

    Please Login or Register  to view this content.

+ 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. Replies: 5
    Last Post: 09-01-2014, 03:55 PM
  2. Replies: 7
    Last Post: 05-02-2013, 06:48 AM
  3. Add number from one cell to a running total cell depending on the day of the week
    By Mrmild in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-27-2013, 12:17 PM
  4. Macro to save a file with a pre file name + week number from a cell
    By The.Dutchmaster in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-06-2012, 03:54 PM
  5. Paste to Specific Sheet Depending Upon Week Number
    By mtt23 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-10-2012, 09:04 PM
  6. Working hours in one week depending week no
    By Zsrinker2 in forum Excel General
    Replies: 2
    Last Post: 06-23-2010, 01:28 PM
  7. Replies: 2
    Last Post: 04-12-2005, 05:06 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