ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Cannot call the worksheet function Weeknum (https://www.excelbanter.com/excel-programming/434579-cannot-call-worksheet-function-weeknum.html)

Michiel via OfficeKB.com

Cannot call the worksheet function Weeknum
 
Anyone who can shine a light on this?

1) Worksheet functions can be called in VBA by using: Application.
WorksheetFunctionName
2) The worksheet function 'WeekNum' Exists
3) It works fine in my worksheet '=WEEKNUM(NOW(),1)'

Based on these I would say this would also work:

Sub WeekDay()
Dim dt As Date

dt = Now()
MsgBox Application.Weeknum(dt, 1)
End Sub

However I get: "Object doesn't support this property or method" (err#438)

I also know the Weeknum can be directly called from VBA by installing the Add-
In. But I just want to use the worksheet function.

Anyone?

--
Message posted via http://www.officekb.com


Mike H

Cannot call the worksheet function Weeknum
 
Hi,

Do it this way


Dt = Now()
MyWeek = DatePart("ww", Dt)

Mike


"Michiel via OfficeKB.com" wrote:

Anyone who can shine a light on this?

1) Worksheet functions can be called in VBA by using: Application.
WorksheetFunctionName
2) The worksheet function 'WeekNum' Exists
3) It works fine in my worksheet '=WEEKNUM(NOW(),1)'

Based on these I would say this would also work:

Sub WeekDay()
Dim dt As Date

dt = Now()
MsgBox Application.Weeknum(dt, 1)
End Sub

However I get: "Object doesn't support this property or method" (err#438)

I also know the Weeknum can be directly called from VBA by installing the Add-
In. But I just want to use the worksheet function.

Anyone?

--
Message posted via http://www.officekb.com



Mike H

Cannot call the worksheet function Weeknum
 
Hi,

I should have added that if you want to use weeknum then try this

MyWeek = Application.Run("ATPVBAEN.XLA!weeknum", dt, 1)

Mike

"Mike H" wrote:

Hi,

Do it this way


Dt = Now()
MyWeek = DatePart("ww", Dt)

Mike


"Michiel via OfficeKB.com" wrote:

Anyone who can shine a light on this?

1) Worksheet functions can be called in VBA by using: Application.
WorksheetFunctionName
2) The worksheet function 'WeekNum' Exists
3) It works fine in my worksheet '=WEEKNUM(NOW(),1)'

Based on these I would say this would also work:

Sub WeekDay()
Dim dt As Date

dt = Now()
MsgBox Application.Weeknum(dt, 1)
End Sub

However I get: "Object doesn't support this property or method" (err#438)

I also know the Weeknum can be directly called from VBA by installing the Add-
In. But I just want to use the worksheet function.

Anyone?

--
Message posted via http://www.officekb.com



Gary''s Student

Cannot call the worksheet function Weeknum
 
Before Excel 2007 use:

MsgBox Evaluate("=WeekNum(Today(),1)")
--
Gary''s Student - gsnu200906

Michiel via OfficeKB.com

Cannot call the worksheet function Weeknum
 
Gents,

Thanks for your reply.
It works!

Great!

ML

Gary''s Student wrote:
Before Excel 2007 use:

MsgBox Evaluate("=WeekNum(Today(),1)")


--
Message posted via http://www.officekb.com



All times are GMT +1. The time now is 04:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com