Results 1 to 13 of 13
  1. #1
    5 Star Lounger Lou Sander's Avatar
    Join Date
    Jun 2002
    Location
    Pittsburgh, PA
    Posts
    855
    Thanks
    140
    Thanked 10 Times in 9 Posts

    Keeping a logbook in Word

    This is a restart of an earlier thread entitled Time Stamp Enhancer. The requirements have been trimmed back, and I have an idea about how to do what needs to be done. Some of it has already been handled in the attached file.

    What is wanted is to be able to keep a logbook in Word. We can be logging anything we want to, but let's imagine we are logging trips to the gym. For each trip, we want to know when we left home. That time will be recorded by a Timestamp initiated by pressing a hotkey when we leave. Then, right after the Timestamp, we enter whatever text we want to have as a log entry. This might be something like "Traffic is bad today."

    At some future time, we want to go back over all the log entries in the document and report how many days ago we made each one. We could call that the ElapsedTimeStamp.

    In the attached document, we create the Timestamp by pressing CTRL+Shift+T. We can then type our log entry. The Timestamp is of the format "??/??/??: " (without quotes), where the ? stands for any number and the other characters stand for themselves. There are a colon and a space after the last number.

    The attached document doesn't have any way to do an ElapsedTimeStamp, but I have some ideas about how to do it. I'm just not good enough to do it in VBA. Here's the process:

    Move to the start of the document and do an Advanced Find using wildcards. Search for "??/??/??: " (without quotes). When one is found, calculate the elapsed time and print it next to the timestamped date. Stop when the end of the document is reached.

    That's it. Maybe this is clearer than it was the last time.
    Attached Files Attached Files
    Lou Sander
    Pittsburgh, Pennsylvania
    USA

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    What constitutes the 'elapsed time', the period between: each date/time; the first and last date/time; something else? And where does the output go: a message box; somewhere in the document (please specify); somewhere else?

    As per your other thread, the macro could be reduced to:
    Code:
    Sub TimeStamp()
    Selection.TypeText Text:=Format(Now, "MM/DD/YYYY hh:mm") & ": "
    End Sub
    or, if you don't want the time:
    Code:
    Sub TimeStamp()
    Selection.TypeText Text:=Format(Now, "MM/DD/YYYY") & ": "
    End Sub
    (you really shouldn't use 2-diigit years).
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    5 Star Lounger Lou Sander's Avatar
    Join Date
    Jun 2002
    Location
    Pittsburgh, PA
    Posts
    855
    Thanks
    140
    Thanked 10 Times in 9 Posts
    The elapsed time is the number of days between the date of the timestamp and now. It doesn't matter a whole lot whether "now" is the current time, the time when the document was last opened, or the time when an update button was pressed. Just as long as it is some recent time, hopefully sometime today.

    The elapsed time should appear right after the original timestamp, probably in parentheses:

    02/14/16: (3 days ago) This is the log entry that was typed after the time was stamped.

    It would be fine, and maybe even preferable, if a dummy elapsed time were printed immediately after the time was stamped. That could give

    02/17/16: (0 days ago) This is the log entry that was typed...

    The whole idea is to relieve the reader of the task of figuring out how long ago the original log entry was made. For current purposes, the number of days ago would be fine.
    Lou Sander
    Pittsburgh, Pennsylvania
    USA

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    And do you want this to:
    a) give the elapsed time for every paragraph that starts with a date;
    b) replace any previous elapsed time outputs?

    PS: I see you have asked about doing the same thing in Excel (http://windowssecrets.com/forums/sho...ok-Application). I'd rather not waste time developing something you're not going to use.
    Last edited by macropod; 2016-02-18 at 00:32.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #5
    5 Star Lounger Lou Sander's Avatar
    Join Date
    Jun 2002
    Location
    Pittsburgh, PA
    Posts
    855
    Thanks
    140
    Thanked 10 Times in 9 Posts
    a) Just give the elapsed time for every place that has a timestamp in the indicated format. Most likely they will be at the start of a paragraph, but it would be good to handle any case where they aren't. If that's not possible, just do it for the ones at the beginning of the paragraph. The unique format of the timestamp could be the key to finding it.

    b) Every elapsed time stamp should be replaced/updated every time the "update" action happens. We want to know how long ago every timestamp was created. One might just be able to search for things in the timestamp format, and provide an elapsed time for each of them.

    There may be a solution in Excel, but Word is by far preferred. I was thinking that date arithmetic might be easier in Excel, and I know a lot more about VBA in Excel, and I know some of the fellows who are active in the Excel forum. But the bottom line is that to me, Word is much easier to work with for entering data in a project like this.

    Just FYI, I'm keeping notes for my physician, logging the incidence of symptoms. Sometimes its a long time between appointments, and I want him to know very easily how long ago I experienced a particular event.
    Lou Sander
    Pittsburgh, Pennsylvania
    USA

  6. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    OK, try the following for the time-stamp:
    Code:
    Sub TimeStamp()
    Selection.TypeText Text:=Format(Now, "MM/DD/YYYY") & ": "
    End Sub
    and, for the elapsed times:
    Code:
    Sub ElapsedTime()
    Application.ScreenUpdating = False
    With ActiveDocument.Range
      With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "([0-9]{2}/[0-9]{2}/[0-9]{4}) \([!\(]@\):"
        .Replacement.Text = "\1:"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchWildcards = True
        .Execute Replace:=wdReplaceAll
        .Text = "[0-9]{2}/[0-9]{2}/[0-9]{4}:"
        .Replacement.Text = ""
        .Wrap = wdFindStop
        .Execute
      End With
      Do While .Find.Found
        .End = .End - 1
        .InsertAfter " (" & Int(Now - CDate(.Text)) & " days ago)"
        .Collapse wdCollapseEnd
        .Find.Execute
      Loop
    End With
    Application.ScreenUpdating = True
    End Sub
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  7. The Following User Says Thank You to macropod For This Useful Post:

    Lou Sander (2016-02-19)

  8. #7
    5 Star Lounger Lou Sander's Avatar
    Join Date
    Jun 2002
    Location
    Pittsburgh, PA
    Posts
    855
    Thanks
    140
    Thanked 10 Times in 9 Posts
    PERFECT! I absolutely couldn't have done it without you. Thanks.

    From what I can see, with a bit of work I will be able to follow your code. I've written short programs in VB 6, and done some tiny things in Excel VBA, but this is the first Word VBA code that I've ever seen, or at least close to the first.

    BTW, yesterday I saw the doc and gave him a manually timestamped record of symptoms. He loved it. I told him I was working with somebody on an "elapsed time stamp", and he thought it would be quite a good idea. I only see him every three months or so, so the elapsed time stuff might be useful as time goes on -- neither of us will have to do any mental date arithmetic.
    Last edited by Lou Sander; 2016-02-19 at 21:24.
    Lou Sander
    Pittsburgh, Pennsylvania
    USA

  9. #8
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    FWIW, The ElapsedTime macro basically uses two wildcard Find/Replace operations: the first to delete all existing elapsed-time records; the second, in conjunction with a loop, to insert a new elapsed-time record for each date.

    On a side note, if there are any dates you don't want the macro to process, you could insert those in a different format (e.g. with - instead of / as the separators, with two-digit years, or with the month as abbreviated text)
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  10. #9
    5 Star Lounger Lou Sander's Avatar
    Join Date
    Jun 2002
    Location
    Pittsburgh, PA
    Posts
    855
    Thanks
    140
    Thanked 10 Times in 9 Posts
    It might be interesting to insert the timestamp and the ElapsedTime in some color other than Automatic. Maybe some sort of lighter gray to make them less obtrusive on the page.

    BTW, I have a Canberra story. In 1958, I was a U.S. Navy junior midshipman. I took my summer cruise in the North Atlantic on USS Canberra (CAG-2), which was a guided missile cruiser and a very snazzy ship in its day. The midshipmen rotated through various menial jobs as the cruise went along. There was suddenly some trouble in Lebanon, and all ships were ordered to stand by for possible action. The midshipmen were frozen in whatever duty they had at the time.

    I was the bell orderly, the guy who rang the ship's bell every half hour during daylight hours. It was a really good job, out in the sun all day long, with only that one duty to perform. I don't remember how long I had that assignment, but I think it might have been one or two weeks. When the Lebanon trouble was over, the midshipmen resumed their normal rotation.

    Fifty years later, probably in 2008 or so, I heard that there is some sort of memorial to USS Canberra in Canberra, ACT. Apparently the very bell that I rung in 1958 is down there on display somewhere. I would REALLY like to get to Oz and see it some day, provided it's still around. I'm afraid I'd have to hit the Lottery first, though.
    Lou Sander
    Pittsburgh, Pennsylvania
    USA

  11. #10
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Quote Originally Posted by Lou Sander View Post
    It might be interesting to insert the timestamp and the ElapsedTime in some color other than Automatic. Maybe some sort of lighter gray to make them less obtrusive on the page.
    After:
    .InsertAfter " (" & Int(Now - CDate(.Text)) & " days ago)"
    you could insert something like:
    .MoveStartUntil "(", wdForward
    .Font.ColorIndex = wdGray50

    I've visited the US & Canada a few times over the last decade; everywhere we go we meet compatriots of yours who want to visit Aus. It's not that far, or expensive for you folk, either - especially with US:AUD exchange rates being what they are ATM.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  12. #11
    New Lounger
    Join Date
    Dec 2009
    Location
    Columbia, Maryland, USA
    Posts
    9
    Thanks
    2
    Thanked 1 Time in 1 Post
    For a quick and dirty log file, you can use Windows' built-in text editor. Open a new text editor file and type .LOG (all caps necessary) then a return. Save the file with whatever .txt file name you like. The every time you open the file, a date and time stamp will be appended, ready for you to create whatever log entry you wish. This has been around since Windows 3.x.

    Pat

  13. #12
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Pat,

    Neat!

    logfile.PNG

    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  14. #13
    WS Lounge VIP access-mdb's Avatar
    Join Date
    Dec 2009
    Location
    Oxfordshire, UK
    Posts
    1,725
    Thanks
    147
    Thanked 156 Times in 149 Posts
    Shame, it doesn't work in Notepad++
    Talk is cheap because supply exceeds demand

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •