Results 1 to 6 of 6
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Launch time (VBA/Word/20003/SP3)

    I have been looking -- unsuccessfully -- for a method to determine when the current session of Word was launched. Is it possible?
    Regards
    Don

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Launch time (VBA/Word/20003/SP3)

    You could have an add-in set a global variable in an AutoExec macro.
    Or create a small text file on the user's hard disk; you can then inspect the FileDateTime of this file.
    Or you could look at the FileDateTime of the ~$Normal.dot file in the user templates folder. But if Word crashes, this file isn't deleted, so I don't know whether its FileDateTime is always dependable.

  3. #3
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Launch time (VBA/Word/20003/SP3)

    Thank you Hans.
    Of course, your response begged another question, but since it had nothing to do with VBA, I have posted it <!post=here,737112>here<!/post>.
    Regards
    Don

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Launch time (VBA/Word/20003/SP3)

    Try this:
    <pre>Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
    Function ProcStartTime() As Date
    Dim objWMIService As Object, objProcess As Object, colProcess As Object
    Dim strComputer As String, strTime As String
    Dim colOutput As Collection
    Dim lngIndex As Long
    Dim lngProcId As Long
    ' local machine
    strComputer = "."

    lngProcId = GetCurrentProcessId

    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!" _
    & strComputer & "rootcimv2")

    ' Note: can't use 'LIKE' keyword in Win 2000;
    ' can in XP, 2003 and, presumably, Vista
    Set colProcess = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where ProcessID = " & lngProcId)
    ' check it's running at all!
    For Each objProcess In colProcess
    strTime = objProcess.properties_("CreationDate")
    Next objProcess
    ProcStartTime = DateSerial(Left(strTime, 4), Mid(strTime, 5, 2), Mid(strTime, 7, 2)) _
    + TimeSerial(Mid(strTime, 9, 2), Mid(strTime, 11, 2), Mid(strTime, 13, 2))
    End Function
    </pre>

    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Launch time (VBA/Word/20003/SP3)

    Hi Rory
    I have tested this on Word 2003 and 2007. I cannot find a way to fool your code. Superb! <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>
    Regards
    Don

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Launch time (VBA/Word/20003/SP3)

    ><post:=737,202>post 737,202</post:>
    I disagree with "W.D. (Don) ". (grin)
    "Superb" is not the right word.
    Nor "Thank You" the right icon.
    <img src=/S/trophy.gif border=0 alt=trophy width=15 height=15> for icons.
    Words fail me.

Posting Permissions

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