Excel Workbook Modules Not Appearing in Workbook Macros - excel

I have a macro-enabled workbook which contains several modules, each module containing a number of macros. My issue is that I open the macro list from the developer tab and no macros for my workbook are there anymore. When I open VBA, I still see them there and associated in the tree to the workbook/project. The macros are still in the modules as well.
Background: Today, after a bit of editing in one of the macros, I closed VBA, got a prompt about a project being reset, I clicked ok. Problems began. All macros in the workbook used to show up from the macros prompt in the developer tab.
Project/Workbook tree with associated modules containing macros; no macros showing in workbook

I think I realized what the problem was. I was having an issue with running a macro to which I decided to recover an earlier version of the workbook and saved over the original. Well, the macros were still hyperlinked to the recovered version of the workbook that had the name extension that included the date/time, therefore "belonging" to that workbook.
My fix: I right clicked the macroed object (button), assign macro, and deleted the hyperlink text and kept only the name of the macro. One by one, all macros were recovered to the workbook. :)

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:

How to remove invallid entries from macro list?

In Excel, when opening the list of macros, there are some invalid entries. How to get rid of them?
Background:
I have an extended VBA library, containing a lot of UDFs and subs. I have added descriptions for UDFs using macro options. Maybe i created these invalid entries accidently in the past by a sub, which parses my code modules and generates descriptions for UDFs if this is provided via comments in the code module. This works fine now.
The invalid entries are actually the names of UDFs which do not exist anymore. They should not have appeared unter macros at any time, but again, maybe I messed up in the past.
I also would like to add some description to macros that do exist - but apparently that is only possible for UDFs?
Clarifications:
There is only this one workbook open. These are not macros of a different workbook. I selected "This Workbook only" for list of macros anyway.
There are no addins.
In VBE under Macros these invalid entires do NOT appear.
In Excel, under Developer Tools->Macros they DO appear.
In Excel, under Developer Tools->Macros, I can not edit or delete or execute these entries. Delete is greyed out, edit and execute lead to a popup error saying: "Der Bezug ist ungültig."
If you are referring to the Macro dialog that opens when clicking View > Macros, then note that there is a drop-down with which you can filter to show macros from a particular workbook only.
Use this to find where the "invalid" macros live, then edit that workbook and handle the macros from there (fix them or remove them).
The Macro dialog box that opens from the Developer tab lists all macros in "All open workbooks" by default. In the dropdown that shows this selection you can select to show macros in only a specific workbook. The reverse of this coin is that you can know exactly where any listed macro is located.
There are buttons to the right of the list which allow you to Edit or Delete any of the listed macros. The Edit button will take you to the module where the macro is stored.
There is also an Options button. When you click that another dialog box opens where you can set shortcuts as well as add a description. You can add a description to any listed macro, whether it's used as UDF or otherwise.
I wonder what would happen if a description exists for a macro that has been deleted. If such a situation is supported by Excel pressing the Delete button should rectify it.
I found an answer on microsoft.com:
https://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel-mso_winother-mso_2016/cannot-delete-macros/8e9072ae-ad95-49cb-952c-3a50b746d0d2
So it appears my workbook got somehow "corrupted". As I said, I did play with it quite a bit during development. So what I did to fix it:
Export all code modules.
Save workbook as .xlsx under a different name.
Open this cleaned xlsx and save it as xlsm again.
Imported all code modules into this cleaned xlsm.
Manually copied code in worksheet from corrupted version to clean version.
Now the macros are gone in the cleaned version.

Excel Open 2 Workbooks at the same time

I have a workbook that I open with vba coding. There are several different userforms to input data and get reports out of this workbook.
It seems that while this workbook is open, and active, I cannot open, to look at and/or edit, an unrelated excel spreadsheet through Windows Explorer. One of my users asked me if while this program is running if she could look at (without closing the active workbook) a different spreadsheet. It has nothing to do with coding such a request into the active workbook, its more for convenience i.e. not having to close this one and open that one.
Is there anything I can do to facilitate this request? Is there some vba code I can use in my active workbook that allows or gives Excel permission to open more than one workbook?
I think you'll find it is when a Userform or any other Excel dialog-based object is open, then you cannot simply "double-click" on an another workbook to open, as Excel is busy and focus on the open dialog screen.
However, if you start another instance of Excel (Start -> All programs -> Microsoft Excel) and then open the workbook from within the new instance, then you work with additional workbooks.

Adding Module through code

I have a master workbook containing a macro which opens another workbook containing a demand forecast. The workbook opened through the macro is downloaded from a customer portal and is all new every day without possibility of editing it beforehand.
The macro then loops through the information and creates new readable and more intuitive worksheets. However, on a few of these worksheets I would like to add some event-driven code to give tooltips when mousing over or selecting cells.
Is there any possibility (without installing add-ons from vanilla Excel 2010) to add code to worksheet objects created during a macro?
The layout of the processed workbook is more or less static, so I was wondering if I should create a template file and then copy the input into it. That would allow me to have coded the events before data is added. Is this the best possibility?
As Dan pointed out, you could use Application.VBE.ActiveVBProject to programmatically add code modules to a workbook. But doing this requires more lenient Macro security settings (which are set to untrusted, by default) and this is not recommended.
When I have to do something similar, I use three workbooks:
The data containing workbook
This book has no macro functionality
A template workbook containing the necessary macros
A macro enabled workbook to facilitate the transition.
Use workbook #3 to open workbook #1 and copy its data into workbook #2. Save a copy of workbook #2 and close it. Repeat this process as necessary.
It isn't the prettiest solution, but it keeps your code modular.

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