|
楼主 |
发表于 2024-2-8 14:13
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
* 下面的代码,是我去年“日期3合1”(date3in1)宏丢失后,我前几天重写的,感觉比过去的好些:
* batmanbbs 老师 可以参看一下,其实查找时我已经糊涂了!但还算全部能找到所有日期。
* 该宏仅预处理有空格和无空格的所有日期,不是正式的处理日期的宏。
- Sub DatePre()
- Const s As String = "[0-90-9 ^s^t一二三四五六七八九十零〇○Oo00Oo]@"
- With ActiveDocument.Content
- Do
- With .Find
- .ClearFormatting
- .Text = "^13" & s & "?" & s & "*^13"
- .Forward = True
- .MatchWildcards = True
- .Execute
- With .Parent
- If Len(.Text) = 0 Then Exit Sub
- .MoveStart
- If .Text Like "[22二]*[日月0-90-9]?" Then
- .Find.Execute "[ ^s^t]", , , 1, , , , , , "", 2
- .CharacterWidth = wdWidthHalfWidth
- If .Text Like "20##年*月*" And Len(.Text) <= 12 Then
- ElseIf .Text Like "20##[!0-9]*#*" And Len(.Text) <= 11 Then
- .Characters(5).Text = "年"
- If .Text Like "*年#?" Or .Text Like "*年##?" Then
- .Characters.Last.InsertBefore Text:="月"
- Else
- If .Text Like "*年#?#?" Or .Text Like "*年#?##?" Then
- .Characters(7).Text = "月"
- ElseIf .Text Like "*年##?#?" Or .Text Like "*年##?##?" Then
- .Characters(8).Text = "月"
- End If
- .Characters.Last.InsertBefore Text:="日"
- End If
- ElseIf .Text Like "二???年*月*" And Len(.Text) <= 13 Then
- Dim t$
- t = .Text
- t = Replace(t, "一", "1")
- t = Replace(t, "二", "2")
- t = Replace(t, "三", "3")
- t = Replace(t, "四", "4")
- t = Replace(t, "五", "5")
- t = Replace(t, "六", "6")
- t = Replace(t, "七", "7")
- t = Replace(t, "八", "8")
- t = Replace(t, "九", "9")
- t = Replace(t, "零", "0")
- t = Replace(t, "〇", "0")
- t = Replace(t, "○", "0")
- t = Replace(t, "O", "0")
- t = Replace(t, "O", "0")
- t = Replace(t, "0", "0")
- t = Replace(t, "0", "0")
- t = Replace(t, "O", "0")
- t = Replace(t, "o", "0")
- If t Like "*年十月*" Then
- t = Replace(t, "十", "10", 1, 1)
- ElseIf t Like "*年十?月*" Then
- t = Replace(t, "十", "1", 1, 1)
- End If
- If t Like "*月?十?日?" Then
- t = Replace(t, "十", "")
- ElseIf t Like "*月十?日?" Then
- t = Replace(t, "十", "1")
- End If
- .Text = t
- End If
- End If
- .Start = .End
- .End = .End - 1
- End With
- End With
- Loop
- End With
- End Sub
复制代码 |
|