Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default UDF Optional variables become required in Add-In

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default UDF Optional variables become required in Add-In

Peter,

Thanks for your reply.

When I save the file as an Add-In i can still call the UDF, however I
need to enter values for all of the "Optional" arguments for it to
work, otherwise i get the #VALUE! error.

I read an article / post suggesting that Optional arguments need to be
declared as variants in an Add-In.
Tried declaring as a string & got the same result.

Any other suggestions would be great.

Cheers

Stuie


On 13 Dec, 10:44, "Peter T" <peter_t@discussions wrote:
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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default UDF Optional variables become required in Add-In

Hi Stuie,

I can't recreate your #VALUE! error with your function in an addin and
omitting the optional arguments in the cell formula. However with missing
variants Cstr(Empty) returns a "Error 448" in the returned string for each
usage.

In your addin make a new function with slightly different name, eg ITEMLIST2
(don't forget to change in the two places where you assign a return value).
Also make the changes I suggested last time (ie variant to string). Does
this work.

Regards,
Peter T

wrote in message
...
Peter,

Thanks for your reply.

When I save the file as an Add-In i can still call the UDF, however I
need to enter values for all of the "Optional" arguments for it to
work, otherwise i get the #VALUE! error.

I read an article / post suggesting that Optional arguments need to be
declared as variants in an Add-In.
Tried declaring as a string & got the same result.

Any other suggestions would be great.

Cheers

Stuie


On 13 Dec, 10:44, "Peter T" <peter_t@discussions wrote:
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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default UDF Optional variables become required in Add-In

Peter,

Apologies, I was being a bit dense!
Didn't realise there was an older version of the Add-In still being
referenced!

Your suggested adjustment works just fine...

Thanks again

Stuie

On 13 Dec, 12:18, "Peter T" <peter_t@discussions wrote:
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
optional calculations roger_the_dodger Excel Worksheet Functions 1 October 6th 08 10:51 PM
Optional hyphen? Eric Excel Discussion (Misc queries) 4 October 19th 06 01:31 AM
Optional Variables Dave Excel Programming 1 June 5th 06 05:25 PM
optional parameter Ben Excel Programming 1 April 21st 06 07:11 PM
Optional Linking Vin81 Excel Discussion (Misc queries) 0 February 21st 06 12:56 AM


All times are GMT +1. The time now is 05:37 AM.

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"