+ Reply to Thread
Results 1 to 4 of 4

Counting how long a Macro takes to run

  1. #1
    Diane Alsing
    Guest

    Counting how long a Macro takes to run

    I have a Macro that Opens, saves & closes a directory of files (to
    automatically update data links, etc). I would like to add a little piece of
    code that takes note of the time the Marco Starts & Stops & displays the time
    it took to run when it is completed.

    I currently have code that displays the quantity of files updated.

    MsgBox "Update Complete. " & Counter & " Files Updated"

    I was wondering if it was possible to perhaps capture the before & after
    times & just subtract them (but I know dates/times in Excel are weird so I'm
    not sure how to do it)

    Thank you.
    Regards,
    Diane

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good afternoon

    Try this:

    Sub Your_macro()

    Dim counter As Single
    counter = Timer

    < Your macro code goes here>

    MsgBox "That took " & Timer - counter & " seconds."

    End sub

    HTH

  3. #3
    Tom Ogilvy
    Guest

    Re: Counting how long a Macro takes to run

    dim sngStart as Single

    sngStart = Now
    - your code

    MsgBox "Update Complete. " & Counter & _
    " Files Updated" & VBNewline &
    " took " & format(now - sngStart,"hh:mm:ss")

    --
    Regards,
    Tom Ogilvy


    "Diane Alsing" <[email protected]> wrote in message
    news:[email protected]...
    > I have a Macro that Opens, saves & closes a directory of files (to
    > automatically update data links, etc). I would like to add a little piece

    of
    > code that takes note of the time the Marco Starts & Stops & displays the

    time
    > it took to run when it is completed.
    >
    > I currently have code that displays the quantity of files updated.
    >
    > MsgBox "Update Complete. " & Counter & " Files Updated"
    >
    > I was wondering if it was possible to perhaps capture the before & after
    > times & just subtract them (but I know dates/times in Excel are weird so

    I'm
    > not sure how to do it)
    >
    > Thank you.
    > Regards,
    > Diane




  4. #4
    Diane Alsing
    Guest

    Re: Counting how long a Macro takes to run

    As always - fantastic! Thanks.

    "Tom Ogilvy" wrote:

    > dim sngStart as Single
    >
    > sngStart = Now
    > - your code
    >
    > MsgBox "Update Complete. " & Counter & _
    > " Files Updated" & VBNewline &
    > " took " & format(now - sngStart,"hh:mm:ss")
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Diane Alsing" <[email protected]> wrote in message
    > news:[email protected]...
    > > I have a Macro that Opens, saves & closes a directory of files (to
    > > automatically update data links, etc). I would like to add a little piece

    > of
    > > code that takes note of the time the Marco Starts & Stops & displays the

    > time
    > > it took to run when it is completed.
    > >
    > > I currently have code that displays the quantity of files updated.
    > >
    > > MsgBox "Update Complete. " & Counter & " Files Updated"
    > >
    > > I was wondering if it was possible to perhaps capture the before & after
    > > times & just subtract them (but I know dates/times in Excel are weird so

    > I'm
    > > not sure how to do it)
    > >
    > > Thank you.
    > > Regards,
    > > Diane

    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1