将日期mm/dd/yyyy转换为mm.dd.yyyy word vba

将日期mm/dd/yyyy转换为mm.dd.yyyy word vba,vba,ms-word,Vba,Ms Word,我有以下日期 2018年2月12日 2/13/2018 2018年2月14日 我需要将上述日期转换为2018年2月12日、2018年2月13日、2018年2月14日,这些日期应加下划线。此代码段将以所需格式将日期插入光标位置,并插入尾随空格 Dim d As String d = "7/25/2011" With Selection .Font.Underline = wdNone ' next text will not be underlined .T

我有以下日期

2018年2月12日 2/13/2018 2018年2月14日


我需要将上述日期转换为2018年2月12日、2018年2月13日、2018年2月14日,这些日期应加下划线。

此代码段将以所需格式将日期插入光标位置,并插入尾随空格

Dim d As String

d = "7/25/2011"
With Selection
    .Font.Underline = wdNone            ' next text will not be underlined
    .TypeText " "                       ' or any separator that will follow the date
    .Collapse                           ' remove selection
    .Start = .Start - 1                 ' set cursor before the separator
    .Collapse                           ' remove selection
    .Font.Underline = wdUnderlineSingle ' next text will be underlined
    .TypeText Format(d, "dd.mm.yyyy")
    .Collapse                ' remove selection and leave the cursor right after the date
End With

你甚至不需要一个宏来完成这项工作-它可以通过一个通配符Find/Replace来完成所有日期,而无需选择任何内容。。。