date显示在msgbox中,但不是用于重命名工作表的variables

我正在尝试重新命名工作表选项卡与上个星期六的date。 我可以得到date以正确显示使用Msgbox。

MsgBox图像

但是,当我尝试在代码中使用相同的variables,它会引发“编译错误:预期:)”。

错误

我知道它正在寻找一个),但我已经从字面上试图把每个位置,但仍然得到错误。 感谢您考虑帮助解决这个问题。 下面是整个子​​程序。

Sub LastSaturdayIntExtMissTime() 'gets the past Saturday's date based on today. Dim iWeekday As Integer, LastSaturdayDate As Date, sfx As String iWeekday = Weekday(Now(), vbSaturday) LastSaturdayDate = Format(Now - (iWeekday - 1), "mm/dd/yyyy") Select Case Right(Day(LastSaturdayDate), 1) Case "1" sfx = """st""" Case "2" sfx = """nd""" Case "3" sfx = """rd""" Case Else sfx = """th""" End Select ActiveWorkbook.Sheets(2).Name = (UCase(Format(Date, "mmm")) & " Data through " & Format(LastSaturdayDate, "mmm d" & sfx) 'this throws a compile error MsgBox Format(LastSaturdayDate, "mmm d" & sfx) 'this works End Sub 

错误的行:

 ActiveWorkbook.Sheets(2).Name = (UCase(Format(Date, "mmm")) & " Data through " & Format(LastSaturdayDate, "mmm d" & sfx) 

在等号前有“(”),应该是:

 ActiveWorkbook.Sheets(2).Name = UCase(Format(Date, "mmm")) & " Data through " & Format(LastSaturdayDate, "mmm d" & sfx)