Excel VBA: NetworkDays Error 2015

Posted by Martin on Stack Overflow See other posts from Stack Overflow or by Martin
Published on 2010-05-19T10:31:40Z Indexed on 2010/05/19 11:00 UTC
Read the original article Hit count: 406

Filed under:
|
|
|

Hi All,

I have the this bit of code in a VBA class which is to workout the number of days between a property of the class (a date) and today’s date.

Dim EmailDate As Date
EmailDate = Me.Email.DateReceived

Debug.Print EmailDate, Date
Debug.Print NetworkDays(EmailDate), Date, Range("BankHolidays"))

When I run it I get the following output

23/04/2010    19/05/2010 
[GetMacroRegId] 'NETWORKDAYS' <
[GetMacroRegId] 'NETWORKDAYS' -> '699990072' >
Error 2015

I have tested it in a module, using dummy data, and get the correct answer. Can anyone see why this would be giving an error in a class?

I have referenced atpvbaen.xls.

Edit: I have found that when I run the code through a menu option I have created on the menu bar it fails, but when I run it via a button or through the VB Editor it works fine. Looks like it is something to do with the menu.

Thanks, Martin

© Stack Overflow or respective owner

Related posts about excel

Related posts about excel-vba