Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

Replacing text (date time string entries)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Odie - 30 Mar 2005 21:03 GMT
I have several documents with several text lines beginning with date time
string entries like:

20000101000000.375 blah blah
20000101000000.888 blah blah
20000101000001.346 blah blah
20000101000001.789 blah blah
20000101000002.104 blah blah
etc

The format is currently YYYYMMDDHHMMSS.SSS
I want to loop through each line and convert it YYYYMMDDSSSSS.SS

In other words replace each hours mins and seconds into total seconds.

Can anyone provide some suggestions?

TIA
Jay Freedman - 31 Mar 2005 03:34 GMT
>I have several documents with several text lines beginning with date time
>string entries like:
[quoted text clipped - 14 lines]
>
>TIA

Like this:

   Dim oRg As Range
   Dim strTime As String
   Dim lngSecs As Long
   
   Set oRg = ActiveDocument.Range
   With oRg.Find
       .ClearFormatting
       .Format = False
       .Forward = True
       .Wrap = wdFindStop
       .MatchWildcards = True
       .Text = "[0-9]{14}."  ' 14 digits and a period
       
       Do While .Execute
           ' skip the date part
           oRg.MoveStart unit:=wdCharacter, Count:=8
           ' strip off the period
           strTime = Left$(oRg.Text, 6)
           ' compute time in seconds
           lngSecs = CLng(Right$(strTime, 2))
           lngSecs = lngSecs + 60 * CLng(Mid$(strTime, 3, 2))
           lngSecs = lngSecs + 3600 * CLng(Left$(strTime, 2))
           ' convert back to a 6-digit string plus period
           oRg.Text = Format(lngSecs, "000000.")
           ' prepare for next find
           oRg.Collapse wdCollapseEnd
       Loop
   End With

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org
Odie - 31 Mar 2005 14:25 GMT
Works perfectly Jay!!   You rock -Thanks!!!! ;)

> >I have several documents with several text lines beginning with date time
> >string entries like:
[quoted text clipped - 50 lines]
> Jay Freedman
> Microsoft Word MVP         FAQ: http://word.mvps.org

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.