Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep reference to add-in UDF when workbook moved to different folder than add-in?

I wrote an Excel add-in that provides UDFs (user-defined worksheet functions).

All is well until one user sends his workbook using those functions to another user, or just tries to use the workbook on more than one computer, where the add-in has been installed to different paths.

Even if the only difference in the paths is the drive letter, when the workbook is opened on the other computer, the old full path appears on the formulas in front of all the UDFs, and the formulas return an error.

One way of dealing with that is doing a search & replace of all formulas in the workbook, replacing the path with an empty string. Then the formulas reset themselves for the add-in's path on the current computer. Sometimes I then have to go into the VBE and run a CalculateFullRebuild to get the formulas to work. Though it works, it's a lot to ask of the less technical users, and it's annoying to have to do it frequently for those users who move their workbooks around a lot.

Also -- do COM add-ins have this problem? My add-in is an xla. Though I'm curious about that, it's a moot point in this case since COM add-ins don't work on Macintosh Excel and I need this add-in to work cross-platform.

UPDATE:

As requested, here's a screenshot:

Screenshot showing path in formula

This screenshot shows what happens if Fred, who put the add-in in C:\Fred's Stuff\Fred's Excel Stuff\MyAddin.xla, sends his workbook to Martha, who put the same add-in in another path, such as C:\Martha's Files\Martha's Excel Files\MyAddin.xla, and Martha opens the file Fred sent.

If Martha deletes the path, leaving only "=MyUDF()" in the formula, Excel will find MyAddin.xla on Martha's computer in the path where Martha put it (assuming she had previously installed MyAddin.xla as an add-in in Excel), and resolve the formula correctly.

like image 897
Greg Lovern Avatar asked Jul 24 '14 04:07

Greg Lovern


People also ask

How do you save user defined functions in Excel?

After you have created the functions you need, click File > Save As. In the Save As dialog box, open the Save As Type drop-down list, and select Excel Add-In. Save the workbook under a recognizable name, such as MyFunctions.

Why a custom function is not working in Excel?

As for the custom ones, Excel cannot validate the VBA code and identify other cells that could also affect the result of the custom function. Therefore, your custom formula may not change when you make changes to the workbook. To fix the issue, you'll just need to use the Application. Volatile statement.

Where is user defined function in Excel?

When you add a function to the workbook using the Insert Function command next to the formula bar, your UDF will appear in the resulting dialog box. The Insert Function dialog box will show your UDF in the category selected.


1 Answers

This is one of the many bugbears Excel developers need to face at one time or another, and there are a few work-arounds for it, but which one you choose will depend on your own circumstances:

http://www.jkp-ads.com/articles/FixLinks2UDF00.asp

In case the link dies, here is a summary of the three suggested methods:

  • Use fixed locations.
  • Instead of keeping your UDF code inside the addin, you create a facility that copies the UDF routine into each workbook that uses it.
  • Redirect the UDFs to the new location.
like image 197
Tim Avatar answered Nov 01 '22 11:11

Tim