VBA を使用して Microsoft Word 2013 でマクロを作成し、日付 (主に日付と月) に先行ゼロを追加しようとしています。
したがって、2004 年 4 月 6 日から 2004 年 4 月 6 日まで、および 2005 年 5 月 11 日から 2005 年 5 月 11 日まで
ここで回答のバリエーションを使用しようとしましたが、最初の日に無限にループします: http://answers.microsoft.com/en-us/office/forum/office_2010-word/macro-to-convert-date-format -in-a-document/20539af7-a961-499f-9e85-22af8f4c3c58?auth=1
Sub ConvertDateFormat()
Dim FoundOne As Boolean
Selection.HomeKey Unit:=wdStory, Extend:=wdMove
FoundOne = True ' loop at least once
Do While FoundOne ' loop until no date is found
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "([0-9]{1,2})[/]([0-9]{1,2})[/]([0-9]{4})"
.Format = True
.Forward = True
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceNone
' check that the find is a date
If IsDate(Selection.Text) Then
Selection.Text = Format(Selection.Text, "dd/mm/yyyy")
Selection.Collapse wdCollapseEnd
Else ' not a date - end loop
FoundOne = False
End If
Loop
End Sub