GMayor, your Code for this is Great. Thanks again.
GMaxey, I must learn how to step through the code. This is in my book. There is so much to learn!
Yes, I have been reading about Range, it is a method and object. I wrote one more macro, and used your oRng ! That part works but I am hung up on the format of DATE.
Perhaps you can save me hours and hours.
I have a date on the top line of my document that looks like this:
CRQ 1234567 Add Contractor None 7/27/2017 9:52:31 AM
I use this code to write it to the document:
Selection.InsertDateTime DateTimeFormat:="M/d/yyyy h:mm:ss am/pm", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
When I am finished with a piece of work, I want to know how many hours, minutes, and seconds it takes to complete. So I wrote this Macro:
Code:
Sub Macro45()
'
' Macro45 Macro
'
'This first part finds the date on the first line of the document and copies it
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "/" ‘Finds the Date
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdWord, Count:=2
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Dim oRng As Range
Set oRng = Selection.Range
oRng.Copy
Dim dtDuration As Date
Duration = DateDiff("s", oRng, Time) 'This is only the seconds
Selection.EndKey Unit:=wdStory
Selection.TypeText Text:="It took this long." & Duration
End Sub