+ Reply to Thread
Results 1 to 5 of 5

Save file with ISO correct Workweek

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-18-2004
    Location
    Portland, Oregon
    MS-Off Ver
    2016
    Posts
    182

    Save file with ISO correct Workweek

    Hello Everyone,

    Last year this portion of my macro worked great assigning the current work week according to ISO standards.

    ActiveWorkbook.SaveAs Application.UserName & "_" & "FCST" & "_" & Format(Date, "MMDDYYYY") & "_" & "CW" & Format(Date, "WW", vbUseSystemDayOfWeek, vbUseSystem)
    Since the change of the year it does not work. For instance, today I ran it and it says we are in work week 3, but ISO says we are in work week 2. I don't know how to fix and I can't seem to find the answer.

    Thoughts?

    Thanks,
    Matt
    Last edited by matt4003; 01-12-2010 at 04:38 PM.

  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: Save file with ISO correct Workweek

    Hello Matt,

    Since the ISO 8601 week and the Gregorian calendar week are not identical, you will need to use a conversion function to return the correct ISO week.

    From Chip Pearson's site http://www.cpearson.com/excel/WeekNumbers.aspx
    Public Function IsoWeekNumber(InDate As Date) As Integer
        Dim D As Long
        D = DateSerial(Year(InDate - Weekday(InDate - 1) + 4), 1, 3)
        IsoWeekNumber = Int((InDate - D + Weekday(D) + 5) / 7)
    End Function
    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
    Forum Contributor
    Join Date
    05-18-2004
    Location
    Portland, Oregon
    MS-Off Ver
    2016
    Posts
    182

    Re: Save file with ISO correct Workweek

    Hi Leith!

    Thanks for the reply.

    I guess I don't know exactly how to insert that into my code....or reference that Function in my ActiveWorkbook.SaveAs statement....

    I put the new Public Function in Module 1 above the ActiveWorkbook.SaveAs Sub, but what do I change on my
    Format(Date, "WW", vbUseSystemDayOfWeek, vbUseSystem)
    Thanks again for your help!

  4. #4
    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: Save file with ISO correct Workweek

    Hello Matt,

    Copy Chip's code in a standard VBA Module. Add this line where you need it...
    ActiveWorkbook.SaveAs Application.UserName & "_" & "FCST" & "_" & Format(Date, "MMDDYYYY") & "_" & "CW" & IsoWeekNumber(Date)

  5. #5
    Forum Contributor
    Join Date
    05-18-2004
    Location
    Portland, Oregon
    MS-Off Ver
    2016
    Posts
    182

    Re: Save file with ISO correct Workweek

    Thanks Leith! I was so close, just missed the last part of "(Date)".

    Works great!

    I will close the thread as Solved.

    Cheers,
    Matt

+ 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