0
votes

I have an Addin that defines some mathematical functions not available in excel. I have it installed and working as it should in the template worksheet (located in the template workbook), but when I copy the template worksheet which contains the function from the template workbook to a new workbook, the addin seems to stop working and gives me a "#NAME?" error in the cell in which the function is called up.

Does anyone know what is going on? Thanks in advance

EDIT: I should have been more specific. The Add in is for a User Defined Function (UDF) and is located in an xla file. Above, when I refer to a "template workbook", this is actually incorrect. Its a normal workbook (.xls), from which we copy individual worksheets as needed, to a new workbook. I'll call this my 'Master' workbook to differentiate from a 'template'.

Since we have a many different 'Master' workbooks from which we extract specific worksheets on a regular basis, I am trying to automate this process of selecting worksheets to copy (using a checkboxs in a worksheet). Once all the necessary checkboxes are ticked, a button is pressed which creates a new workbook and then imports all the required worksheets from the various master workbooks. The UDF's don't work in this new worksheet.

With some prompting from the responders below and extensive web searches, the problem lies with the UDF function reference itself. Let me explain:

The UDF is defined as:

Public Function Ber(ByVal x As Double) As Double End Function

This works fine in the 'Master' TPLATE.xls workbook. When I copy a sheet from this which contains a cell which has the formula, say "=Ber(A1)", in the new sheet, the formula becomes: "=TPLATE.xls!Ber(A1)".

If I then manually renter the correct UDF in the Cell's formula, it works. I dont want to have to do this.

I have found once promising solution, but cant seem to get it to work: http://www.jkp-ads.com/Articles/FixLinks2UDF00.asp (Note: Click on the arrow in the green box to continue the article)

Are there any ways to ensure that the UDF's in the copied worksheet retain the correct reference to the Addin?

I have tried the following:

  1. Including code to find and replace any text between the "=" sign and the "Ber(A1)" with just "=Ber(A1)" -> Doesn't work

  2. The solution from the link above. -> cant get it to work.

Thanks again for any assistance!

2
What kind of addin do you have? Some sort of UDF, COM, document level? The error you are getting means that Excel cannot find one of the references you are using. It could be a named range error reference that is missing (did you have any workbook named ranges defined that didn't get copied over?) or it could be that it cannot find your addin (function call or something).Mitja Bezenšek

2 Answers

1
votes

A better solution would be to put the UDF code in an XLA/XLAM addin rather than in a worksheet template. See this link for instructions

http://www.cpearson.com/excel/createaddin.aspx

1
votes

I think I have found a solution and would like some input from others:

I created a routine to update the links where the UDF is called.

Sub updatelinks()
    ActiveWorkbook.ChangeLink Name:= _
        "C:\Users\user.1\AppData\Roaming\Microsoft\AddIns\BesselAddIn.xla", NewName _
        :=Application.UserLibraryPath & "BesselAddIn.xla", Type:=xlExcelLinks
End Sub

When I call this just after importing the worksheet into the new workbook (while the sheet is still active), it seems to do the job for some computers, but not all.

This all makes me think that when a UDF is called, then the machinery hidden inside Excel includes, but doesn't typically display, the full path name of the Addin location.

Is any of this making sense?