- Sub 领导值班()
- Dim x$, y$, a&, b$, c&, d&, i&, p$, q$
- x = InputBox("", "起始日期 - 2020/7/17", "2020/7/17")
- If x = "" Then End
- y = InputBox("", "截止日期 - 2020/8/25", "2020/8/25")
- If y = "" Then End
- a = DateDiff("d", x, y) + 1
- b = InputBox("", "领导人数", "3")
- If b = "" Then End
- If Not (b Like "[1-9]" Or b Like "[1-9][0-9]") Then End
- ReDim arr(0 To b - 1)
- c = Int(a / b)
- d = a - b * c
- For i = 1 To b
- arr(i - 1) = c
- Next
- For i = 1 To d
- arr(i - 1) = c + 1
- Next
- Documents.Add
- With Selection
- .TypeText Text:="共值班" & a & "天!" & vbCr
- For i = 1 To b
- If i = 1 Then p = x Else p = DateAdd("d", 1, q)
- q = DateAdd("d", arr(i - 1) - 1, p)
- .TypeText Text:=i & "号领导(" & arr(i - 1) & "天) " & p & "—" & q & vbCr
- Next
- End With
- With ActiveDocument.Content.Find
- .Execute "([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})", , , 1, , , , , , "\1年\2月\3日", 2
- If MsgBox("是否删除年份?", 4 + 16) = vbYes Then .Execute "[0-9]{4}年", , , 1, , , , , , "", 2
- End With
- End Sub
复制代码 |