+ Reply to Thread
Results 1 to 3 of 3

How to safe a file with calendar week in the name (WeekNum function)

Hybrid View

  1. #1
    Registered User
    Join Date
    01-05-2023
    Location
    Berlin
    MS-Off Ver
    2013
    Posts
    2

    Question How to safe a file with calendar week in the name (WeekNum function)

    Hello,

    I am creating a simple macro with a part where the file gets saved with the current calendar week and a name from cell B2:

    Path = "P:\Martin\LT"
    filename = "LT CW02 " & Range("B2")
    ActiveWorkbook.saveAs filename:=Path & filename & ".xlsm", FileFormat:=xlNormal


    Above code works and it gets saved correctly, but every week I will have to change the code to the current calendar week. Is there a way how to change it so that I can use WeekNum function? I tried following but does not work:

    filename = "LT CW" & WeekNum(TODAY(), 21) & Range("B2")

    Probably I cannot use normal Excel functions in VBA code, but I am not sure how to work it out, as I have only basic knowledge of VBA so far.

    Thank you for help.

    Martin

  2. #2
    Valued Forum Contributor
    Join Date
    11-29-2022
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    435

    Re: How to safe a file with calendar week in the name (WeekNum function)

    Good news! You CAN use normal Excel functions in VBA

    filename = "LT CW" & WeekNum(TODAY(), 21) & Range("B2") translated to working VBA is below. Change SheetName as needed.

    filename = "LT CW " & Application.WeekNum(Date, 2) & " " & ThisWorkbook.Sheets("SheetName").Range("B2")

  3. #3
    Registered User
    Join Date
    01-05-2023
    Location
    Berlin
    MS-Off Ver
    2013
    Posts
    2

    Re: How to safe a file with calendar week in the name (WeekNum function)

    wow. Thank you for your fast reply, I will try it next week at work and will let you know..
    Have a good day

+ 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] how to convert weeknum to start and end date of the week
    By dogbural in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 08-09-2020, 08:12 AM
  2. [SOLVED] Using WeekNum with leading zero on single number week
    By mowens74 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-22-2018, 08:44 AM
  3. Replies: 5
    Last Post: 12-05-2017, 07:39 PM
  4. [SOLVED] Calculating stats by week instead of month - WEEKNUM?
    By Beginner9 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-11-2014, 11:56 AM
  5. weeknum week ending on friday?
    By randalino in forum Excel General
    Replies: 4
    Last Post: 03-19-2009, 10:21 AM
  6. Replies: 4
    Last Post: 12-12-2005, 11:35 AM
  7. Replies: 3
    Last Post: 06-13-2005, 01:05 PM

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