![]() |
#1
|
|||
|
|||
![]()
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 |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Calculate time over two dates | Diver | Excel | 3 | 07-22-2017 11:31 PM |
![]() |
aymanharake | Excel | 6 | 02-17-2017 04:22 PM |
Calculate Time in Hours and Percent | pabyford | Excel | 6 | 12-13-2016 12:29 PM |
![]() |
Catherine | Project | 1 | 02-19-2014 11:15 AM |
![]() |
jrasche2003@yahoo.com | Excel | 2 | 02-09-2007 07:10 AM |