<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Calculate Working Hours in VBA</title>
	<atom:link href="http://www.codeforexcelandoutlook.com/blog/2008/06/calculate-working-hours-in-vba/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codeforexcelandoutlook.com/blog/2008/06/calculate-working-hours-in-vba/</link>
	<description>Automation and VBA code for Microsoft® Excel and Outlook</description>
	<lastBuildDate>Sun, 21 Mar 2010 08:54:13 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: JP</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/06/calculate-working-hours-in-vba/#comment-2317</link>
		<dc:creator>JP</dc:creator>
		<pubDate>Thu, 28 Jan 2010 23:19:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=67#comment-2317</guid>
		<description>You can retrieve default start and end time from the registry. Check out the following registry key:

HKCU\Software\Microsoft\Office\11.0\Outlook\Options\Calendar

Of course, you&#039;ll change 11.0 to reflect your version number (Outlook 2003 is 11.0, 2007 is 12.0 and so on).

Look for the DWORD values &quot;CalDefStart&quot; and &quot;CalDefEnd&quot;

The challenge will be to interpret the DWORD values into something meaningful. You&#039;ll need to adjust the values and see how the DWORD values change, to make some kind of conversion algorithm.</description>
		<content:encoded><![CDATA[<p>You can retrieve default start and end time from the registry. Check out the following registry key:</p>
<p>HKCU\Software\Microsoft\Office\11.0\Outlook\Options\Calendar</p>
<p>Of course, you'll change 11.0 to reflect your version number (Outlook 2003 is 11.0, 2007 is 12.0 and so on).</p>
<p>Look for the DWORD values "CalDefStart" and "CalDefEnd"</p>
<p>The challenge will be to interpret the DWORD values into something meaningful. You'll need to adjust the values and see how the DWORD values change, to make some kind of conversion algorithm.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/06/calculate-working-hours-in-vba/#comment-2314</link>
		<dc:creator>Jon</dc:creator>
		<pubDate>Wed, 27 Jan 2010 16:42:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=67#comment-2314</guid>
		<description>Thanks!  Would be so cool to be able to do!  I&#039;m still searching too, will post here to update if I find a way before I hear back.  :)</description>
		<content:encoded><![CDATA[<p>Thanks!  Would be so cool to be able to do!  I'm still searching too, will post here to update if I find a way before I hear back.  <img src='http://www.codeforexcelandoutlook.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JP</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/06/calculate-working-hours-in-vba/#comment-2312</link>
		<dc:creator>JP</dc:creator>
		<pubDate>Wed, 27 Jan 2010 12:09:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=67#comment-2312</guid>
		<description>I&#039;ll check it out.</description>
		<content:encoded><![CDATA[<p>I'll check it out.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/06/calculate-working-hours-in-vba/#comment-2310</link>
		<dc:creator>Jon</dc:creator>
		<pubDate>Wed, 27 Jan 2010 07:02:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=67#comment-2310</guid>
		<description>It is possible to enter your normal Working Hours in Outlook, in the general Calendar settings (at least in the new 2010 version, but I think in 2007 also).  Is there a way to read this schedule from Outlook VBA in order to automatically determine the normal working hours as specified there, without having to manually specify what they are?</description>
		<content:encoded><![CDATA[<p>It is possible to enter your normal Working Hours in Outlook, in the general Calendar settings (at least in the new 2010 version, but I think in 2007 also).  Is there a way to read this schedule from Outlook VBA in order to automatically determine the normal working hours as specified there, without having to manually specify what they are?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Whitney</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/06/calculate-working-hours-in-vba/#comment-1426</link>
		<dc:creator>Whitney</dc:creator>
		<pubDate>Thu, 29 Oct 2009 15:37:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=67#comment-1426</guid>
		<description>Hi,

Can this formula be modified to calculate a work day of 8:00am until 5:00pm excluding lunch time from 12:00pm to 1:00pm?

Thanks,
Whitney</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Can this formula be modified to calculate a work day of 8:00am until 5:00pm excluding lunch time from 12:00pm to 1:00pm?</p>
<p>Thanks,<br />
Whitney</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Praba</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/06/calculate-working-hours-in-vba/#comment-1425</link>
		<dc:creator>Praba</dc:creator>
		<pubDate>Thu, 25 Jun 2009 06:08:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=67#comment-1425</guid>
		<description>Hi,

I hv 1 minor issue.Need to calculate the value for 2 date

Start Date: 5/31/2009 13:30
End Date: 6/1/2009 18:01
i require the result in HH:MM
this is to calculate the working hours
exceeding 24 hours or less

seek yr support


Thanks in advance</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I hv 1 minor issue.Need to calculate the value for 2 date</p>
<p>Start Date: 5/31/2009 13:30<br />
End Date: 6/1/2009 18:01<br />
i require the result in HH:MM<br />
this is to calculate the working hours<br />
exceeding 24 hours or less</p>
<p>seek yr support</p>
<p>Thanks in advance</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JP</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/06/calculate-working-hours-in-vba/#comment-1424</link>
		<dc:creator>JP</dc:creator>
		<pubDate>Fri, 03 Apr 2009 21:53:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=67#comment-1424</guid>
		<description>I think you should use the new version of this function. I rewrote it so you don&#039;t need to reference any libraries, and it&#039;s more accurate. Here&#039;s a link:

&lt;a href=&quot;http://www.codeforexcelandoutlook.com/blog/2009/03/time-difference-testing/&quot; rel=&quot;nofollow&quot;&gt;Time Difference Testing&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>I think you should use the new version of this function. I rewrote it so you don't need to reference any libraries, and it's more accurate. Here's a link:</p>
<p><a href="http://www.codeforexcelandoutlook.com/blog/2009/03/time-difference-testing/" rel="nofollow">Time Difference Testing</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cynthia</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/06/calculate-working-hours-in-vba/#comment-1423</link>
		<dc:creator>Cynthia</dc:creator>
		<pubDate>Fri, 03 Apr 2009 18:47:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=67#comment-1423</guid>
		<description>HI Again,

I figured out how to get the results in the appropriate cells; this being said, I am now getting the infamous #VALUE result.  I am working with Excel 2007.  I went to the Office Button, clicked on the Excel Options button, went to Add-Ins, and selected the Analysis tool Pak VBA, which now shows as an Active Application Add-In.  I then went into the VBE, and went to Tools&gt;References&gt; and checked beside atpvbaen.xls.  My code is in the same workbook as my formula.  Help!  Here is my code:

[cc lang=&#039;vb&#039;]Private Function TimeDiff(StartTime As Variant, EndTime As Variant) As Variant
&#039;
&#039; calculates time different between two dates/times provided as arguments
&#039; i.e. &quot;1/1/2008 12:00 AM&quot; and &quot;1/13/2008 10:33 AM&quot;
&#039;
&#039; based on 8 hour workday, excluding holidays and weekends and non-working hours
&#039;
Dim StartDate As Date
Dim EndDate As Date
Dim ModStartTime As Date
Dim ModEndTime As Date
Dim DaysWorked As Long
Dim HolidaysList()

Const HoursPerDay As Integer = 24

&#039; 24-hour military time, edit as needed
&#039; if you want to set different working hours
Const ComeIn As Date = &quot;9:00&quot;
Const Leave As Date = &quot;17:00&quot;

&#039; list of federal holidays in 2009
&#039; add or remove as you see fit
&#039; you will need to add additional year&#039;s holidays as well
&#039; remove ones you aren&#039;t using
HolidaysList = Array(&quot;10/13/2008&quot;, &quot;11/11/2008&quot;, &quot;11/27/2008&quot;, &quot;12/25/2008&quot;, &quot;1/1/2009&quot;, &quot;1/19/2009&quot;, &quot;2/16/2009&quot;, &quot;5/25/2009&quot;, &quot;7/4/2009&quot;, &quot;9/7/2009&quot;, &quot;10/12/2009&quot;, &quot;11/11&#039;2009&quot;, &quot;11/26/2009&quot;, &quot;12/25/2009&quot;)
&#039;October 13, 2008
&#039;November 11, 2008
&#039;November 27, 2008
&#039;December 25, 2008
&#039;January 1, 2009
&#039;January 19, 2009
&#039;February 16, 2009
&#039;May 25, 2009
&#039;July 4, 2009
&#039;September 7, 2009
&#039;October 12, 2009
&#039;November 11, 2009
&#039;November 26, 2009
&#039;December 25, 2009

StartDate = Int(StartTime)
EndDate = Int(EndTime)

&#039; http://www.bygsoftware.com/issues/modbug.html
ModStartTime = StartTime - 1 * Int(StartTime / 1)
ModEndTime = EndTime - 1 * Int(EndTime / 1)

If (EndDate - StartDate) &lt; 1 Then
&#039; it&#039;s the same day, just calculate simple hours diff
    TimeDiff = Format(HoursPerDay * (ModEndTime - ModStartTime), &quot;####.####&quot;)
Else
    &#039; adapted from http://www.ozgrid.com/News/apr-2008.htm
    TimeDiff = (NetworkDays(StartDate, EndDate, HolidaysList) - 1) * (HoursPerDay * (Leave - ComeIn)) - _
        (HoursPerDay * (Leave - ModEndTime)) - (HoursPerDay * (ModStartTime - ComeIn))
End If

End Function
End Function[/cc]</description>
		<content:encoded><![CDATA[<p>HI Again,</p>
<p>I figured out how to get the results in the appropriate cells; this being said, I am now getting the infamous #VALUE result.  I am working with Excel 2007.  I went to the Office Button, clicked on the Excel Options button, went to Add-Ins, and selected the Analysis tool Pak VBA, which now shows as an Active Application Add-In.  I then went into the VBE, and went to Tools>References> and checked beside atpvbaen.xls.  My code is in the same workbook as my formula.  Help!  Here is my code:</p>
<div class="codecolorer-container vb default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:630px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000080;">Private</span> <span style="color: #000080;">Function</span> TimeDiff(StartTime <span style="color: #000080;">As</span> <span style="color: #000080;">Variant</span>, EndTime <span style="color: #000080;">As</span> <span style="color: #000080;">Variant</span>) <span style="color: #000080;">As</span> <span style="color: #000080;">Variant</span><br />
<span style="color: #008000;">'<br />
</span><span style="color: #008000;">' calculates time different between two dates/times provided as arguments<br />
</span><span style="color: #008000;">' i.e. &quot;1/1/2008 12:00 AM&quot; and &quot;1/13/2008 10:33 AM&quot;<br />
</span><span style="color: #008000;">'<br />
</span><span style="color: #008000;">' based on 8 hour workday, excluding holidays and weekends and non-working hours<br />
</span><span style="color: #008000;">'<br />
</span><span style="color: #000080;">Dim</span> StartDate <span style="color: #000080;">As</span> <span style="color: #000080;">Date</span><br />
<span style="color: #000080;">Dim</span> EndDate <span style="color: #000080;">As</span> <span style="color: #000080;">Date</span><br />
<span style="color: #000080;">Dim</span> ModStartTime <span style="color: #000080;">As</span> <span style="color: #000080;">Date</span><br />
<span style="color: #000080;">Dim</span> ModEndTime <span style="color: #000080;">As</span> <span style="color: #000080;">Date</span><br />
<span style="color: #000080;">Dim</span> DaysWorked <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span><br />
<span style="color: #000080;">Dim</span> HolidaysList()<br />
<br />
<span style="color: #000080;">Const</span> HoursPerDay <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span> = 24<br />
<br />
<span style="color: #008000;">' 24-hour military time, edit as needed<br />
</span><span style="color: #008000;">' if you want to set different working hours<br />
</span><span style="color: #000080;">Const</span> ComeIn <span style="color: #000080;">As</span> <span style="color: #000080;">Date</span> = <span style="color: #800000;">&quot;9:00&quot;</span><br />
<span style="color: #000080;">Const</span> Leave <span style="color: #000080;">As</span> <span style="color: #000080;">Date</span> = <span style="color: #800000;">&quot;17:00&quot;</span><br />
<br />
<span style="color: #008000;">' list of federal holidays in 2009<br />
</span><span style="color: #008000;">' add or remove as you see fit<br />
</span><span style="color: #008000;">' you will need to add additional year's holidays as well<br />
</span><span style="color: #008000;">' remove ones you aren't using<br />
</span>HolidaysList = Array(<span style="color: #800000;">&quot;10/13/2008&quot;</span>, <span style="color: #800000;">&quot;11/11/2008&quot;</span>, <span style="color: #800000;">&quot;11/27/2008&quot;</span>, <span style="color: #800000;">&quot;12/25/2008&quot;</span>, <span style="color: #800000;">&quot;1/1/2009&quot;</span>, <span style="color: #800000;">&quot;1/19/2009&quot;</span>, <span style="color: #800000;">&quot;2/16/2009&quot;</span>, <span style="color: #800000;">&quot;5/25/2009&quot;</span>, <span style="color: #800000;">&quot;7/4/2009&quot;</span>, <span style="color: #800000;">&quot;9/7/2009&quot;</span>, <span style="color: #800000;">&quot;10/12/2009&quot;</span>, <span style="color: #800000;">&quot;11/11'2009&quot;</span>, <span style="color: #800000;">&quot;11/26/2009&quot;</span>, <span style="color: #800000;">&quot;12/25/2009&quot;</span>)<br />
<span style="color: #008000;">'October 13, 2008<br />
</span><span style="color: #008000;">'November 11, 2008<br />
</span><span style="color: #008000;">'November 27, 2008<br />
</span><span style="color: #008000;">'December 25, 2008<br />
</span><span style="color: #008000;">'January 1, 2009<br />
</span><span style="color: #008000;">'January 19, 2009<br />
</span><span style="color: #008000;">'February 16, 2009<br />
</span><span style="color: #008000;">'May 25, 2009<br />
</span><span style="color: #008000;">'July 4, 2009<br />
</span><span style="color: #008000;">'September 7, 2009<br />
</span><span style="color: #008000;">'October 12, 2009<br />
</span><span style="color: #008000;">'November 11, 2009<br />
</span><span style="color: #008000;">'November 26, 2009<br />
</span><span style="color: #008000;">'December 25, 2009<br />
</span><br />
StartDate = Int(StartTime)<br />
EndDate = Int(EndTime)<br />
<br />
<span style="color: #008000;">' http://www.bygsoftware.com/issues/modbug.html<br />
</span>ModStartTime = StartTime - 1 * Int(StartTime / 1)<br />
ModEndTime = EndTime - 1 * Int(EndTime / 1)<br />
<br />
<span style="color: #000080;">If</span> (EndDate - StartDate) &lt; 1 <span style="color: #000080;">Then</span><br />
<span style="color: #008000;">' it's the same day, just calculate simple hours diff<br />
</span> &nbsp; &nbsp;TimeDiff = Format(HoursPerDay * (ModEndTime - ModStartTime), <span style="color: #800000;">&quot;####.####&quot;</span>)<br />
<span style="color: #000080;">Else</span><br />
&nbsp; &nbsp; <span style="color: #008000;">' adapted from http://www.ozgrid.com/News/apr-2008.htm<br />
</span> &nbsp; &nbsp;TimeDiff = (NetworkDays(StartDate, EndDate, HolidaysList) - 1) * (HoursPerDay * (Leave - ComeIn)) - _<br />
&nbsp; &nbsp; &nbsp; &nbsp; (HoursPerDay * (Leave - ModEndTime)) - (HoursPerDay * (ModStartTime - ComeIn))<br />
<span style="color: #000080;">End</span> <span style="color: #000080;">If</span><br />
<br />
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span><br />
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></div></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: JP</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/06/calculate-working-hours-in-vba/#comment-1422</link>
		<dc:creator>JP</dc:creator>
		<pubDate>Fri, 03 Apr 2009 18:42:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=67#comment-1422</guid>
		<description>Cynthia,
Assuming your values were placed in A1, B1 and C1:

Column D would be
=TimeDiff(A1,B1)
Column E would be
=TimeDiff(B1,C1)
Column F would be
=TimeDiff(A1,C1)</description>
		<content:encoded><![CDATA[<p>Cynthia,<br />
Assuming your values were placed in A1, B1 and C1:</p>
<p>Column D would be<br />
=TimeDiff(A1,B1)<br />
Column E would be<br />
=TimeDiff(B1,C1)<br />
Column F would be<br />
=TimeDiff(A1,C1)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cynthia</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/06/calculate-working-hours-in-vba/#comment-1421</link>
		<dc:creator>Cynthia</dc:creator>
		<pubDate>Fri, 03 Apr 2009 15:28:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=67#comment-1421</guid>
		<description>Looking for some help - still very new to VBA.  I got the code copied, my start time and open time and holidays all inputted, but not sure what to do next, as it&#039;s not a standard macro (as far as I can tell!).  I have activated the add-in as well, as you instructed.

I have a date/time in columns A, B, &amp; C.  I need to calculate 3 TAT (turnaround time) values:
A to B, B to C, and A to C.

How do I get the values to show up in columns D, E, and F?

This is probably a basic user question, but I would really appreciate any direction you can provide.</description>
		<content:encoded><![CDATA[<p>Looking for some help &#8211; still very new to VBA.  I got the code copied, my start time and open time and holidays all inputted, but not sure what to do next, as it's not a standard macro (as far as I can tell!).  I have activated the add-in as well, as you instructed.</p>
<p>I have a date/time in columns A, B, &#038; C.  I need to calculate 3 TAT (turnaround time) values:<br />
A to B, B to C, and A to C.</p>
<p>How do I get the values to show up in columns D, E, and F?</p>
<p>This is probably a basic user question, but I would really appreciate any direction you can provide.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
