Can you Create a Userform Add In

Hmerman

Board Regular
Joined
Oct 2, 2016
Messages
102
Hello,
I have a Userform that is a calculator to calibrate a water pump or tractor irrigation nozzle.
What I want to know is, can I save this as an Add In whereby the Userform can be showed in any workbook? If possible, how do I go about doing it?

I have saved it as a Add In and ticked the right box, but when I call the Add In, I get a message that the macro is not available in this workbook or that macro's are disabled (which are enabled).

My code also refers to Activeworkbook and - cell. I also saved the following code (which I found on the net) in Thisworkbook to install the Add In button:

Code:
Private Sub Workbook_AddinInstall()
    With Application.CommandBars("Formatting").Controls.Add
        .Caption = "KaliRekenaar"  'The button caption
        .Style = msoButtonCaption
        .OnAction = "kaliRekenaar"  'The Macro name you want to trigger
    End With
End Sub

Private Sub Workbook_AddinUninstall()
    On Error Resume Next
        Application.CommandBars("Formatting").Controls("KaliRekenaar").Delete
    On Error GoTo 0
End Sub

In the AddInInstall code:

Code:
The Application.CommandBars("Formatting").Controls.Add.OnAction
macro that I Call is the
Code:
Userform1.Show
method

Regards,
 
Last edited:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
I don't know what your middle code block means.

Your Workbook_AddInInstall includes this line:

.OnAction = "kaliRekenaar"

This means you need a sub called "kaliRekenaar" which calls the UserForm:

Code:
Sub kaliRekenaar()
    Userform1.Show
End Sub
 
Upvote 0
Your Workbook_AddInInstall includes this line:

.OnAction = "kaliRekenaar"

This means you need a sub called "kaliRekenaar" which calls the UserForm:

Yes you are correct, the full middle line
Code:
Application.CommandBars("Formatting").Controls.Add.OnAction = "kaliRekenaar"

Calls a sub with the same name "kaliRekenaar" with code

Code:
 Userform1.Show

Sorry should have written it more clearly.

I saved it as an Add In, but when I call the Add In, I get a message that the macro is not
available in this workbook or that macro's are disabled (which are
enabled).

Any idea why this would happen?
 
Last edited:
Upvote 0
You still did not say it clearly.

This code adds a button which when clicked (OnAction) runs the sub "kaliRekenaar":

Code:
Private Sub Workbook_AddinInstall()
    With Application.CommandBars("Formatting").Controls.Add
        .Caption = "KaliRekenaar"  'The button caption
        .Style = msoButtonCaption
        .OnAction = "kaliRekenaar"  'The Macro name you want to trigger
    End With
End Sub

In fact, you could probably get rid of the _AddInInstall and _AddInUninstall procedures, and replace it with these:

Code:
Private Sub Workbook_Open()
    With Application.CommandBars("Formatting").Controls.Add
        .Caption = "KaliRekenaar"  'The button caption
        .Style = msoButtonCaption
        .OnAction = "kaliRekenaar"  'The Macro name you want to trigger
    End With
End Sub

Private Sub Workbook_BeforeClose()
    On Error Resume Next
        Application.CommandBars("Formatting").Controls("KaliRekenaar").Delete
    On Error GoTo 0
End Sub

The following is redundant. I don't know where you put it, but you don't need it, and in fact it might be causing trouble:

Code:
Application.CommandBars("Formatting").Controls.Add.OnAction = "kaliRekenaar"

What do you mean "call" the add-in? How are you trying to "call" the add-in?

Save the file as an add-in, and close the file. Then install the add-in, which puts the button into the Add-Ins tab of the ribbon. To run the code, click the "KaliRekenaar" button.
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top