Function WeekDayStrToSolarDate(DateStr As String) As Date
'根据某年某月的第几周的星期几字符串返回当日日期
'如:WeekDayStrToSolarDate("20090621")返回2009年6月第二个星期日的日期06/14/2009
'如果第7位是5的话,返回此月最后一个
Dim Y As Integer, M As Byte, N As Byte, W As Byte
Dim tempDate As Date, tempW As Integer
Dim AddDay As Integer
Y = Left(DateStr, 4): M = Mid(DateStr, 5, 2): N = Mid(DateStr, 7, 1): W = Mid(DateStr, 8, 1)
If N < 5 Then '第N个
tempDate = DateSerial(Y, M, 1)
tempW = Weekday(tempDate)
AddDay = (N - 1) * 7 + (W - tempW)
If tempW > W Then AddDay = AddDay + 7
WeekDayStrToSolarDate= DateAdd("D", AddDay, tempDate)
Else '最后一个
tempDate = DateSerial(Y, M + 1, 1)
tempW = Weekday(tempDate)
AddDay = W - tempW
If tempW <= W Then AddDay = AddDay - 7
WeekDayStrToSolarDate= DateAdd("D", AddDay, tempDate)
End If
End Function