0

我已经看到如何遍历一年中的几周,w1301、w1302、w1303,如果我在周数上循环 +,我可以获得周数,但我相信有一种方法可以直接用 vba 每周循环,我希望至少.

   DateSerial(Year(Now), Month(Now), Day(Now)) To DateSerial(2013, 3, 1)

    StartDate = #1/1/2013#
    EndDate = #12/31/2013#

  For DateLooper = StartDate To EndDate

我从 date 得到了一个星期数的函数

     Public Function IsoWeekNumber(d1 As Date) As Integer
     Attributed to Daniel Maher
     Dim d2 As Long
     d2 = DateSerial(Year(d1 - WeekDay(d1 - 1) + 4), 1, 3)
     IsoWeekNumber = Int((d1 - d2 + WeekDay(d2) + 5) / 7)
     End Function
4

3 回答 3

1

您可以只使用DateAdd 函数

For i = 1 To 52  
    Debug.Print DateAdd("ww", i, Now())  
Next i
于 2013-08-28T23:48:05.337 回答
0

一天的整数值为 1,因此您可以像这样按周迭代:

startDate = #1/1/2013#
endDate   = #12/31/2013#

For d = startDate To endDate Step 7
  'do stuff
Next

星期数可以用DatePart函数确定,例如:

WScript.Echo DatePart("ww", Now)

这适用于

于 2013-08-29T13:39:57.157 回答
0

我尝试了这个解决方案,它似乎有效,我不是 100% 确定它如何处理不同月份的 28、30、31 天,但我相信 vba。我知道我可能犯了一个错误:))

  currentDate = "2013-01-02"    ' coz i wanted to start on a wednesday
  for week = 1 to 52
  debug.print currentDate
  currentDate = DateAdd("ww",1,currentDate)
  next week
于 2013-08-29T20:57:44.553 回答