1
votes

I have a macro which registers my user-defined functions, places them in custom categories and supplies descriptions, called AddUDFsToCategory. This macro is placed in a module in an add-in I have installed. However, for the UDFs to become registered, I have to run the macro manually every time I open Excel.

I want this macro to run when I open Excel, even though no workbook is open. I tried to use the Workbook_AddinInstall in the "ThisWorkbook" section of the addin,

Private Sub Workbook_AddinInstall()
    AddUDFsToCategory
End Sub

but that doesn't seem to achieve anything.

If I try to use it with Workbook_open,

Private Sub Workbook_Open()
    AddUDFsToCategory
End Sub

I get:

"Run-time error '1004': Cannot edit a macro on a hidden workbook. Unhide the workbook using the Unhide command."

Does anyone know how to get around this?

2

2 Answers

0
votes

You should be able to register it through the Excel Options menu.

First, go to options then click on Add-Ins:

enter image description hereenter image description here

From This point, you should be able to manage your add-ins by clicking Go.

enter image description here


You should also try managing your Add-Ins within the VBE itself.

Open VBE and Click Add-ins:

enter image description here

Here you will find the Add-ins manager. Select your add-in and ensure that the checkbox that says "Load on Startup" is selected.

0
votes

The only way I've found to get around this error is to force Excel to have a workbook open when I'm trying to register the UDFs.

Sub AddUDFsToCategory()
   Dim wbkTemp As Excel.Workbook

   If Application.ActiveWorkbook Is Nothing Then
      Set wbkTemp = Application.Workbooks.Add
   End If

   '/--------------------------------------------\
   ' Code to register your User Defined Functions
   '\--------------------------------------------/

   If Not wbkTemp Is Nothing Then
      wbkTemp.Close False
   End If
End Sub