Running macros using command buttons with Add-In

glbcpa

New Member
Joined
Jun 17, 2013
Messages
2
I have been working on this problem for several days almost non-stop.

Is it possible to have a spreadsheet where all the VBA code is contained in an Add-In (.xlam)? The code contains both Functions and Subroutines. The Subroutines are invoked using command buttons on the original spreadsheet (.xlsx or .xlsm).

When I test this setup, the functions work but when I click the command button I receive the standard macro not found or disabled error. Tried Application.Run ("xxx.xlam!subname") but no joy.

Any suggestions? Thanks in advance.

BTW, the reason is to distribute the spreadsheet and have the code in add-in to make it less vulnerable to be able to view and therefore change the code, which would botch everything.

Spreadsheet has 15 tabs, many functions and about 3000 lines of VBA.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
You would need:
Code:
Application.Run "'xxx.xlam'!subname"
if the real add-in name contains spaces.
 
Upvote 0
Yeah, that's what I thought too as I described above (no spaces in .xlam file) but it didn't work.

The code associated with the macro:

Sub macro1()
Application.Run ("test.xlam!macro1")
End Sub

Just tried something else though

Sub MacroTest1
Application.Run ("test.xlam!macro1")
End Sub

Then assigned the command button in the original spreadsheet (.xlsm) to run MacroTest1 instead of Macro1 and it worked. Maybe the double reference was confusing it?

Anyway, thanks for the quick reply. Is my theory of using an add-in to hide code workable, or at least better than just password protecting the VBAProject in the .xlsm file?
 
Upvote 0
It's probably marginally better at deterring a casual user. ;)
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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