View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default UDF Optional variables become required in Add-In

What do you mean by "as soon as I save the Workbook as an Add-In the
Optional variables become Required!". Eg, the 'Optional' prefixes are
removed in the list of function arguments, an error occurs when used as a
UDF and if so where does it error, can't find the name of the UDF in a cell
formula, or something else.

In passing I'd change

Optional ByVal ITEM_PREFIX As Variant, Optional ByVal ITEM_SUFFIX As Variant
pStrList = pStrList & CStr(ITEM_PREFIX) & CStr(pRngCell.Value) &
CStr(ITEM_SUFFIX)

to

Optional ByVal ITEM_PREFIX As String, Optional ByVal ITEM_SUFFIX As String
pStrList = pStrList & ITEM_PREFIX & CStr(pRngCell.Value) & ITEM_SUFFIX

Regards,
Peter T

wrote in message
...
Hello there...

I've written a UDF that allows me to concantenate a range of cell
values with a prefix & suffix value. See below:



Public Function ITEMLIST(ByVal CELL_RANGE As Range, Optional ByVal
ITEM_PREFIX As Variant, Optional ByVal ITEM_SUFFIX As Variant) As
String
'#### Concatenate range of cells, incorporating specified prefix &
suffix values ####

Dim pRngCell As Range
Dim pStrList As String

On Error GoTo errCode

For Each pRngCell In CELL_RANGE
pStrList = pStrList & CStr(ITEM_PREFIX) & CStr(pRngCell.Value)
& CStr(ITEM_SUFFIX)
Next
ITEMLIST = pStrList
Exit Function

errCode:
ITEMLIST = "# Unable to list!"
End Function


The problem i have is that it works fine in an Excel Workbook, but as
soon as I save the Workbook as an Add-In the Optional variables become
Required!

If anyone can shed any light on this i'd be very grateful...

Rgds

Stuie