Date change in Word document

twckfa16

New Member
Joined
Dec 17, 2012
Messages
31
Hello -

I am trying find date occurrences in a Word document from Excel. The format of the date is 'ddmmmyy'.
(Example: 17SEP18). I want to be able to replace with the current date.

This is what I have so far (probably much simpler than this)

Code:
Dim regexp As New RegExp
Dim prevdate As String
Dim pattern As String
pattern = "(^[0-9]{2})([A-Z]{3})([0-9]{2})"

With ActiveDocument.Content
     With regexp 
           .Global = True
           .IgnoreCase = False
           .pattern = pattern
           .Replace

That's all I have so far. Have tried different things with no luck.

Thanks!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "<[0-9]{2}[A-Za-z]{3}[0-9]{2}>"
    .Replacement.Text = UCase(Format(Now(), "DDMMMYY"))
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top