函数作用:自动获取指定月的工作日
'################################################################
Sub 自动填充工作日(month1 As Integer)
'获取指定月份天数
Dim days As Integer
Dim xdate As Date
xdate = CDate("2008-" + CStr(month1))
'初始化公共变量Col2的值
col2 = 4
'调用自定义Mday()函数获取指定月份的天数
days = MDay(xdate)
'循环获取指定月份的工作日
For i = 1 To days
'声明变量保存指定日期
Dim Curdate As String
Curdate = "2008-" + CStr(month1) + "-" + _
CStr(i)
'判断指定日期是否为工作日
If Weekday(CDate(Curdate)) <> vbSaturday _
And Weekday(CDate(Curdate)) <> vbSunday Then
Cells(2, col2) = i
col2 = col2 + 1
End If
Next i
End Sub
'获取指定月份的天数
Public Function MDay(Optional xdate _
As Variant = 0) As Integer
If IsDate(xdate) Then
MDay = Day(DateSerial(Year(xdate), _
Month(xdate) + 1, 0))
Else
MDay = 0
End If
End Function