What is the procedure to run macro stored in my addin from thisworkbook:

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi, what is the procedure to run macro stored in my addin from thisworkbook...
Is there any special way to do this?
Is there any thing i have to keep in mind when running macro stored in my addin?

Thanks for helping in advance.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi, what is the procedure to run macro stored in my addin from thisworkbook...
Is there any special way to do this?
Is there any thing i have to keep in mind when running macro stored in my addin?

Thanks for helping in advance.


You have many options :

OPTION 1

1- Change the Addin Project name from the default VBAProject to a different name to uniqually identify it via the VBE Properties window

2- Set a reference to the new addin project via the VBE tools - References window.

you can then run all the Public macros in your addin

Something like this :

Code:
Call MyAddin.Macro
Where MyAddin is the name of the Addin Project (Changed as described above) and the Macro is the Addin macro to run.
The good thing about this method is that you gain the Intellsense functionality when writing code.The bad thing is that this approach could cause problems if the reference is missing.

OPTION2
Another way is to have the addin Macro declared as Public and located in the addin workbook module then you can call it something along these lines :

Code:
Dim oAddin As Workbook

Set oAddin = GetObject(AddIns("AddinName").FullName)

Call oAddin.Macro
where AddinName is the name of the addin.

OPTION3

Yet another way is by using the Application Run Method such as :

Code:
Application.Run ("AddinName.xla!Macro")
The Run Method allows you to flexibly run macros in standard modules even Private Macros so it is more flexible and no need for any references to be preset.

Maybe other options exist as well.


EDITED: In fact all the above remains true for calling Macros in other open workbooks not just in Addins.
 
Last edited:
Upvote 0
Jaafar, thank you for the very useful information...'m sure this is going to help other users too....

Thank you very much!:)
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

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