Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-07-2017, 10:20 AM
rakesh seebaruth rakesh seebaruth is offline underline  date Windows 10 underline  date Office 2010 64bit
Novice
underline  date
 
Join Date: Jul 2017
Posts: 2
rakesh seebaruth is on a distinguished road
Default underline date

hi guys

i have the following vba codes which converts dates to dd.mm.yyyy

Sub GetDateAndReplace()
Dim FoundOne As Boolean

Selection.HomeKey Unit:=wdStory, Extend:=wdMove
FoundOne = True ' loop at least once



Do While FoundOne ' loop until no date is found
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "([0-9]{1,2})[/]([0-9]{1,2})[/]([0-9]{4})"
.Format = True
.Forward = True
.MatchWildcards = True
End With

Selection.Find.Execute Replace:=wdReplaceNone

' check the find to be sure it's a date
If IsDate(Selection.Text) Then
Selection.Text = Format(Selection.Text, "dd.mm.yyyy")
Selection.Collapse wdCollapseEnd
Else ' not a date - end loop
FoundOne = False
End If
Loop

End Sub

i want vba to underline the dates which have been converted to dd.mm.yyyy

thanks/regards

rakesh
Reply With Quote
  #2  
Old 07-07-2017, 06:12 PM
gmaxey gmaxey is offline underline  date Windows 7 32bit underline  date Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

You make things harder than they have to be:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 7/7/2017
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "([0-9]{1,2})[/]([0-9]{1,2})[/]([0-9]{4})"
    .Format = True
    .Forward = True
    .MatchWildcards = True
    While .Execute
      With oRng
        If IsDate(.Text) Then
          .Text = Format(oRng.Text, "dd.mm.yyyy")
          .Font.Underline = True
        End If
        .Collapse wdCollapseEnd
      End With
    Wend
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
underline  date Wriggly red underline kirkm Word 3 09-18-2016 07:50 PM
underline  date Hyperlinks: Removing Underline reRanger Word 2 08-04-2016 02:29 AM
underline  date Underline a tab Futsal1st Word 2 10-25-2015 05:31 PM
underline  date Underline at bottom of page won't go away yachts66 Word 3 08-13-2014 07:28 AM
underline  date Hyperlink - delete underline Savana PowerPoint 5 04-13-2011 12:34 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:39 AM.


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