Cannot execute macro module - excel

I am currently working on creating my own Ribbon in excel. I wrote out the specific code in a module in a macro-enabled workbook that I will subsequently save as an Excel add-in (.xlam). However, whenever I try to run the module in my macro enabled workbook, the select macro window appears and no code is executed (see picture for reference). Subsequently, I think this is what is also causing my ribbon button to give the following error when clicked "The macro may not be available in this workbook or all macros may be disabled."
Any help/suggestions would be appreciated. Thanks.

Related

create and distribute Excel add in

I have created an extensive macro in excel, that I now want to distribute. I decided I want to do this by saving the macro as add in to a shared network, where all of my collegues have access to it. This way maintaining the macro will be way easier, as I am sure that there are plenty of updates, and bugfixing to come.
I have never created an add in before, so I read several online tutorials + stack overflow questions about it. Up until now I always saved my macros in personal.xlsb, likewise with the macro I now want to save as add in.
My first attempt was to simply save the workbook, where I run the macro, as .xlam, which did not work (I guess because the macro was not saved in that workbook, but in the personal.xlsb).
So I deleted the macro from the personal.xlsb, opened a new workbook, opened the VBA editor, created a new module in that workbook and inserted my code. I then saved the workbook as .xlam. I checked that in the VBA Editor the IsAddin is set to True.
From here it gets confusing somehow. When I open the .xlam file there are no worksheets in it, the add-in is loaded, but the macro does not show up in "Macros", even though the code shows up in the Editor.
When
However the .xlam is still empty when I open it - no code to be seen.
When I open another workbook and load the add-in, in the VBA editor the add-in does show up, and the module with the code of the macro is there as well. But when I click on "macro" it does not show up.
When I open a different Excel file, the add-in is loaded as well (in Excel-add-ins the box is ticked), the module does not show up, and in the VBA editor the .xlam also does not show up.
I have saved, closed, opened, and restarted several times. I have checked if the add-in is saved anywhere else - it was, but I deleted all .xlam files (as non of them worked anyway), and repeated my attempts stated above. When I load the .xlam from the shared network it seems to save itself into the addin folder of microsoft (I guess that is what it should do when it is loaded).
I would really appreciate if someone could help me with how to properly set this up.
I have:
a VBA code that runs fine, when I run it as macro.
I want
to save it to a shared network as add-in, and get it to run.
Edit1:
the add-in shows up in the active add-ins section in options:

Macros invisible to excel, but can be run from ribbon if already established, and appear in VBA editor

I have some macros attached to buttons in the Quick Access Ribbon. All but one of the buttons have been functioning normally, so I'm not sure when this started.
I tried to use a less-used macro button this morning called Unhide All Sheets and it threw this error:
Cannot run the macro 'PERSONAL.XLSB!UnhideAllSheets.UnhideAllSheets'. The macro may not be available in this workbook or all macros may be deleted."
So I went to review my code and all my macros are invisible from the front-end. I select Developer -> Macros, the list is completely empty, and when I attempt to create new buttons on the Quick Access Toolbar, the macro list there is also completely empty.
When I hit Alt + F11 to open the VBA editor, I can see and update macros in specific workbooks and in my personal workbook. Most of them still run, although the offending macro (UnhideAllSheets) throws an Unexpected Error (35005) when run from the editor.
Anybody ever seen this before? I've been googling for an hour with no results.
Most Macro Buttons still work
Nothing on the Macro List
Customize Ribbon can't see the macros
Still visible and functioning in VBA Editor (except for "UnhideAllSheets")
I have same issue and I manually checked/marked atpvbaen in the tools>references. This has solved my problem !
I was facing a similar issue, where some buttons were working and some weren't. What I noticed was my module's name was similar to my procedure's (macro's) name. I'm not aware of the reason, but I when ensured procedures names' are different than the module names.

Is there a way to share a Excel VB Macro as a tool for all future workbooks?

I made a VB script that re-formats data exported to excel from a website so that it is compatible with a geocoder. As of now every export I have to go in, past the VB code run it and save the changes. I am wondering if there is a way to make the VB code available as a tool for all workbooks so it is just a matter of opening the xls file clicking a button and saving it?
To expand a little on BigBen's comment:
Open the Excel file with your code in. Open a new blank Workbook. Open up the VBA Editor (Alt-F11).
Drag the module which contains your code to the new workbook (in the left-hand navigator pane). You should see it add to this new Workbook.
Save you new workbook as MyFunctions (or whatever name you fancy) but choose the "Excel Add-in (*.xlam)" file type. You should see a new file appear in your folder as MyFunctions.xlam.
Back in Excel, from the File menu, choose Options (right at the bottom). And then Add-Ins from the left-hand list. At the bottom will be a drop-down box "Manage: Excel Add Ins". Hit Go...
You'll a list of the add-ins that your Excel knows about: some will be checked (that is they will be loaded at start-up) and some not.
Choose Browse, and navigate to wherever you saved MyFunctions.xlam. And double click on it. You may get a security warning (as your addin doesnt have a digital signature) but just go ahead and enable it (as you wrote the code: this is not blanket advice!). Close Excel (this remembers your choices).
When you next open Excel you should see your add-in file open in the VBA Editor, and your macros and UDFs available in whatever worksheet you are using.

macro in right click menu for all workbooks

I wrote several macro with SAP scripting and other features.
For few of my macros, i need to select a cell, and then run the macro.
All these macros are stored in a add in, hence all my macros are available on every workbook.
I would like to share my addin with my colleagues but I would like to make the macros available from the right click menu.
All pieces of code found here and elsewhere indicate to have a piece of code located in "thisworkbook" tab. Hence the custom right click menu is only available on a specified workbook.
Is it possible to have my macro stored in my add-in accesibble from right click menu for all workbook that I open/use ? like the macro ribbon ?
thank you

Can you refer to an external macro with excel?

I have a reasonably complex macro that I need to run on multiple different excel sheets, this macro is updated periodically and whenever a change is made its necessary to change it in each individual excel sheet. is there a way to get each excel document to refer to the one macro?
for example if i had a hierarchy like this:
DOCUMENTS:
-xlsheet1.xls
-xlsheet3.xls
-xlsheet2.xls
MACROS:
-macro1.bas
where there was a button in each sheet that ran macro1 when clicked.
I would recommend either moving that macro to your personal file or create an Add-In
Working with Personal File
Topic: Create and save all your macros in a single workbook
Link: https://support.microsoft.com/en-us/office/create-and-save-all-your-macros-in-a-single-workbook-66c97ab3-11c2-44db-b021-ae005a9bc790
Quote from the above link:
When you first create a macro in a workbook, it works only in that workbook. But what if you want to use the macro in other workbooks? To make your macros available every time you open Excel, you can create them in a workbook called Personal.xlsb. That’s a hidden workbook stored on your computer, which opens in the background every time you open Excel.
Creating an Add-In
Topic: Creating Excel Add-ins
Link: http://www.ozgrid.com/VBA/excel-add-in-create.htm
Quote from the above link:
I am often asked by users 'what is the best way to distribute their macros?' My answer, is without doubt via an Excel Add-in. After all, this is what Add-ins are for. For those that are not sure what an Excel add-in is, it's is nothing more than an Excel Workbook that has been saved as an Add-in, File>Save as \ Microsoft Excel Add-in (*.xla). Once saved and re-opened the Workbook will be hidden and can only be seen in the "Project Explorer" via the Visual Basic Editor. It is NOT hidden in the same way as the Personal.xls as this can be seen (and made visible) via Windows>Unhide.
The Personal file is good for having a macro across any number of workbooks on a single computer. In a networked environment with multiple users, you could simulate the Personal file by having a single workbook with your macros in it and coding all other workbooks to open and hide this workbook when they start up.

Resources