Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-13-2015, 02:52 AM
shaunlthomas shaunlthomas is offline Assistance with VBA Code to identify and highlight dates in a word doc Windows 8 Assistance with VBA Code to identify and highlight dates in a word doc Office 2013
Novice
Assistance with VBA Code to identify and highlight dates in a word doc
 
Join Date: Aug 2015
Posts: 1
shaunlthomas is on a distinguished road
Exclamation Assistance with VBA Code to identify and highlight dates in a word doc

Hi all. I am hoping someone can help me.

I want to write a code that quality checks work to some degree.



Firstly it needs to identify dates in format D MMMM YYYY

if the date goes over a page break i would like it to highlight the date in yellow.
If the date's year is in the future, highlight the date.

any help would be appreciated:

starting with this:

Sub ChangeDateFormatWithReplaceCommand()

Dim myMonth(1 To 12) As String

myMonth(1) = "January"
myMonth(2) = "February"
myMonth(3) = "March"
myMonth(4) = "April"
myMonth(5) = "May"
myMonth(6) = "June"
myMonth(7) = "July"
myMonth(8) = "August"
myMonth(9) = "September"
myMonth(10) = "October"
myMonth(11) = "November"
myMonth(12) = "December"

For i = 1 To 12
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "([0-9]{1,2})& ")" & "(" & myMonth(i)"
.Replacement.Text = "?""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next i

End Sub

Thanks
Reply With Quote
  #2  
Old 08-13-2015, 05:25 PM
macropod's Avatar
macropod macropod is offline Assistance with VBA Code to identify and highlight dates in a word doc Windows 7 64bit Assistance with VBA Code to identify and highlight dates in a word doc Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could do that with a macro like:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "<[0-9]{1,2} [JFMASONDanuryebchpilgstmov]{3,9} [12][0-9]{3}>"
    .Replacement.Text = ""
    .Forward = True 
    .Format = False
    .Wrap = wdFindStop
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found = True
    If .Characters.First.Information(wdActiveEndAdjustedPageNumber) _
      <> .Characters.Last.Information(wdActiveEndAdjustedPageNumber) Then
      .HighlightColorIndex = wdBrightGreen
    End If
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
but I'd have to question why you're doing this. If the aim is to ensure the dates are not split across page boundaries, you could use a macro like:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = "<([0-9]{1,2}) ([JFMASONDanuryebchpilgstmov]{3,9}) ([12][0-9]{3})>"
  .Replacement.Text = "\1^s\2^s\3"
  .Forward = True
  .Format = False
  .Wrap = wdFindContinue
  .MatchWildcards = True
  .Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
PS: When posting code, please use the code tags, indicated by the # button on the posting menu.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
date



Similar Threads
Thread Thread Starter Forum Replies Last Post
Require assistance in writing code to login to webmail account. saurabhlotankar Excel Programming 4 05-21-2015 10:47 AM
Assistance with Word 2010 If formula ciresuark Word 1 03-09-2015 12:57 PM
Assistance with VBA Code to identify and highlight dates in a word doc Help with VBA code to find and highlight text mpdsal Word VBA 8 09-11-2014 03:55 PM
Code to add dates terricritch Excel Programming 10 11-08-2011 09:51 AM
find - reading highlight - highlight all / highlight doesn't stick when saved bobk544 Word 3 04-15-2009 03:31 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:20 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft