Runtime error 1004- When trying to save a file with saveas command

  • I am trying to save the workbook with below name but getting this error that is attached below

    Code
    1. a = Format(Date, "yy") 'current year
    2. b = Left("FW 30 - 2021", 5)                            
    3. d = Date - Weekday(Date)                              'previous week date
    4. wknum = Int((6 + Day(d + 1 - Weekday(d - 1))) / 7) 'week number of date d
    5. mon = Format(d, "mmm") 'Month of d
    6. 'Debug.Print a; b; d; wknum; mon
    7. mwb.SaveAs ("C:\Users\cap\Ecom \C-Recaps\FY" & a & "" & b & "----" & "wk" & wknum & "---Wk" & " End" & d)
  • You need to format d when using it in the filename otherwise it will probably include invalid characters. You should also include a FileFormat argument so that Excel knows what format you want.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why