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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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