Reputation: 60841
i have an add-in called book1. inside the addin there is a module called module1 which has a sub called addin1
i would like to run the macro addin1 from a different workbook
i am trying to call this macro like this:
Call Addin1
but that's not working
and i tried:
Call book1.xlam.Module1.AddIn1
which is not working either
does anyone know how to run a macro that is within an add-in ?
Upvotes: 8
Views: 60811
Reputation: 51
In relation to how to run subroutines in installed add-ins (.xlam):
Make sure the VBA project associated with the add-in has a unique name (not VBAProject) - say Addin_1.
Within the VBA project for the workbook from which you wish to call the subroutines in the add-in, set a reference to Addin_1. Tools > References, find Addin_1 in the list of available references, and click on the adjacent box (a tick appears).
Within a subroutine in a code module of your workbook, you can now call a subroutine of the add-in, using:
Call Addin_1.routine_name(routine parameters)
Since you have a reference to Addin_1, the names of the subroutines in the add-in will appear once you type Call Addin_1.
and the parameter list for the specific subroutine will appear once you have typed Call Addin_1.routine_name(
, which greatly assists in writing error-free code.
Tested with Excel 2013. Discovered when I was curious to see what happened when I set a reference to the VBA project of an installed add-in (.xlam). I have not seen this documented.
Upvotes: 4
Reputation: 487
In addition to Jacob G's answer - if your .xlam book is protected by password, you should open it for edit (i.e. enter password). Otherwise macros of the .xlam book will not be visible in "Choose Commands From Dropdown"
Upvotes: 1
Reputation: 3665
(Assuming Office 2007) Here's an example:
1- Open a new Workbook.
2- Add a macro that contains the code MsgBox("Add-In")
3- Save as xlam file.
4- Open new Workbook.
5- Click Office Button -> Excel Options
6- Click the Add-Ins tab on the left.
7- At the bottom, next to the "Manage" dropdown, select "Excel Add-Ins" and click Go.
8- Click Browse and navigate to your xlam file.
9- Ensure the box next to your file is checked and click Ok.
10- Click the Office Button -> Excel Options.
11- Click Customize Tab.
12- Select Macros in the "Choose Commands From Dropdown."
13- Double click your AddIn and now a button will appear on the Quick Access Toolbar.
14- Click the button and your message box will now show.
Upvotes: 18
Reputation: 50057
In your workbook you write:
Sub test()
' from other excel file
Application.Run ("youraddin.xla!ShowForm")
End Sub
And in the addin you have
Public Sub ShowForm()
loginform.Show
End Sub
Upvotes: 8
Reputation: 1984
I believe this is what your looking for :) You'll need all the single quotes and ! in the right places, can be a little tricky.
run "'book1'!module1"
Upvotes: 1