Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Force use of standard function

Hi,
I have a class module that has a function called Year(). Normally, this is
fine but in the class module I use the standard vba function Year() to
extract the year from a date. However, vba thinks that this is the class
modules Year() function. How can I tell it to use the standard Year()
function without changing the name of the Year() function in my class module.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Force use of standard function

Seriously Mark, rename your function. I am not saying there isn't a way
round this but its a bad idea to have a procedure of yours with the same name
as a standard VB function.

"Mark Olsen" wrote:

Hi,
I have a class module that has a function called Year(). Normally, this is
fine but in the class module I use the standard vba function Year() to
extract the year from a date. However, vba thinks that this is the class
modules Year() function. How can I tell it to use the standard Year()
function without changing the name of the Year() function in my class module.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Force use of standard function

Mark,

You can't have it both ways, so RENAME your function:

Sub Test()
MsgBox myYear("1/2/2007")
End Sub

Function myYear(inDate As Date) As Integer
myYear = Year(inDate)
End Function

HTH,
Bernie
MS Excel MVP


"Mark Olsen" wrote in message
...
Hi,
I have a class module that has a function called Year(). Normally, this is
fine but in the class module I use the standard vba function Year() to
extract the year from a date. However, vba thinks that this is the class
modules Year() function. How can I tell it to use the standard Year()
function without changing the name of the Year() function in my class module.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Force use of standard function

Best not to name functions same as VBA's functions. However this appears to
work -

' normal module
Sub test()
Dim c As New Class1

MsgBox c.Year(2&) & vbCr & _
Year(4&) & vbCr & _
VBA.DateTime.Year(Date)

End Sub

Function Year(n As Long) As Long
Year = n + 2000
End Function

'code in Class1
Public Function Year(n As Long) As Long
Year = n + 2000
End Function

Regards,
Peter T


"Mark Olsen" wrote in message
...
Hi,
I have a class module that has a function called Year(). Normally, this

is
fine but in the class module I use the standard vba function Year() to
extract the year from a date. However, vba thinks that this is the class
modules Year() function. How can I tell it to use the standard Year()
function without changing the name of the Year() function in my class

module.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Force use of standard function

You shouldn't use VBA reserved words as function names. However,
you can force VBA to use its own function by including the VBA
library name:

Dim Res As Integer
Res = VBA.Year(whatever)

When you are calling your own Year function from within the class
module, use

Res = Me.Year(whatever)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Mark Olsen" wrote in
message
...
Hi,
I have a class module that has a function called Year().
Normally, this is
fine but in the class module I use the standard vba function
Year() to
extract the year from a date. However, vba thinks that this is
the class
modules Year() function. How can I tell it to use the standard
Year()
function without changing the name of the Year() function in my
class module.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Force use of standard function

You can't have it both ways, so RENAME your function:

Actually you can have it both ways. Use

VBA.Year for the VBA function and
Me.Year for the class module function.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Mark,

You can't have it both ways, so RENAME your function:

Sub Test()
MsgBox myYear("1/2/2007")
End Sub

Function myYear(inDate As Date) As Integer
myYear = Year(inDate)
End Function

HTH,
Bernie
MS Excel MVP


"Mark Olsen" wrote in
message
...
Hi,
I have a class module that has a function called Year().
Normally, this is
fine but in the class module I use the standard vba function
Year() to
extract the year from a date. However, vba thinks that this
is the class
modules Year() function. How can I tell it to use the
standard Year()
function without changing the name of the Year() function in
my class module.





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
function to force date? alex Excel Worksheet Functions 2 February 26th 07 02:38 PM
Force function to show positive or negative number? smoore Excel Worksheet Functions 3 March 3rd 06 08:34 PM
How to force a wrap text function when the cell is big enough to p Jason Bathon Excel Discussion (Misc queries) 1 April 13th 05 03:21 PM
Force standard chart size waxwing Excel Programming 1 December 8th 04 02:09 AM
standard function in userfunction? Loranga[_2_] Excel Programming 1 August 12th 04 11:41 AM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"