This is the way to do this with the built-in health check for dates:
Dim OldString, NewString OldString = "31.12.2008" Dim myRegExp Set myRegExp = New RegExp myRegExp.Global = True myRegExp.Pattern = "(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.]((19|20)[0-9]{2})" If myRegExp.Test Then NewString = myRegExp.Replace(OldString, "$2.$1.$3") Else ' A date of for instance 32 December would end up here NewString = "Invalid date" End If
source share