View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Edwin Tam (MS MVP) Edwin Tam (MS MVP) is offline
external usenet poster
 
Posts: 48
Default Explaining an addin

Let's learn by examples! Below are two custom worksheet functions created using VBA

The first example is a simple function for finding out whether a specific year is a leap year. Observe the syntax for the use of arguement, and also the definition of the value type for the function. (Here, the function returns a Boolean value, either TRUE or FALSE.

'------------------------------------------------
Function ISLEAPYEAR(ByVal year_input as integer) As Boolea
If year_input Mod 4 < 0 The
ISLEAPYEAR = Fals
ElseIf year_input Mod 400 = 0 The
ISLEAPYEAR = Tru
ElseIf year_input Mod 100 = 0 The
ISLEAPYEAR = Fals
Els
ISLEAPYEAR = Tru
End I
End Functio
'------------------------------------------------

The second example finds out the "standard font" defined in Excel. Here, there is an "Optional Arguement". See the syntax and how to define a "default value" for the optional arguement

'------------------------------------------------
Function STDFONT(Optional show_size As Boolean = False) As Strin
'the optional arguement decides whether the standard font size is also shown
STDFONT = Application.STANDARDFON
If show_size = True Then STDFONT = STDFONT & " " & Application.STANDARDFONTSIZE & "pt
End Functio
'------------------------------------------------

Also, you may have a look at the Excel VBA on-line help. Look for the key word "Function statement"


----- EMR Tech wrote: ----

How do I define the arguments in an Excel Addin function that I created? When I bring up a built in Excel functio
it does have an expalantion of the arguments. How do I do it for my add-ins? I 'm using Office 2003