I built some macros and save the VBA project as .xlam (Excel Add In) file. The macros (Public Subs) are visible when I go to Excel > File > Options > Quick Access Toolbar(QAT) > Choose 'Macros' from the left drop-down menu. Then I can add the macros to the QAT so users can click the tools icon to run those macros.
I observed a VERY strange behavior. Here's what it was before, everything was normal.
Here's what it was after. Things start getting weird.
The only difference is I changed a Sub's argument type from a built-in variable type to a custom class type. But I haven't run the macro yet. I'm just entering the code. But Excel changed the display on two other macros I'm NOT editing (macro names are Check() and CheckAndFix()).
So the questions are:
1) Why Excel GUI displays different formats while I'm entering the code? And it seem to depends on the variable type I'm typing? I didn't know that IntelliSense had such an influence on the Excel user interface.
2) Why Excel changed the display of two other Subs that I didn't touch?
By the way, this behavior is reproducible even after computer reboot. i.e. I can change the argument type between String and cSettings and observed the macro list format changed accordingly.
Thank you!
I finally figure it out!
Whenever the code referencing an undefined data type, QAT customization won't work. The symptoms are:
1) You'll see the workbook name was prefixed to the macro name on the list. While in normal situation, you'll just see the macro name.
2) If you associate the macro to a QAT button. That button won't work. Whenever you click the button, it will say "Cannot run the macro'XXX'. The macro may not be available in this workbook or all macros may be disabled". This is misleading as the macro is there and all macro is allowed.
You may ask - "Why your code references some undefined data type?" It was because my code reference some additional data types (such as Dictionary) that requires additional library (such as "Microsoft Scripting Runtime). If the library reference was not manually configured, the data type will become 'undefined'.
I'm surprised that the program didn't throw compile error or runtime error. Instead, it gave the message "macro may not be available for this workbook".
Related
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.
Can anyone please help me with excel issue. I have created a dynamic dashboard in excel using sumifs on data layer and index match functions on presentation layer. I have placed a simple List box form control with no VBA or macro.
My dashboard was working fine, without any issue, but on final step I was just trying to make the List box control float on the sheet with scrolling.
I found a vba code, I opened vba from developer mode, pasted code, but that deleted same.
Since then upon any selection of List box item, it is giving me error “ Cannot run the macro Listbox4_Change. The macro May not be available in this workbook or all macros disabled.”
I have tried pretty much every thing I found on google. Created a macro and deleted, copied one line code in all sheets of vba and deleted, enabled Macro security setting, but nothing really is working .
I am stuck badly.
It sounds like you've added a macro and then removed it, but haven't removed the macro assignment on the list box.
Right-click on the control and choose Assign Macro, delete the Macro name, and hit OK.
This is a tough one.
We developed an Excel VBA AddIn. That's an *.xlam file.
This AddIn is quite complex and transforms Excel into a software of it's own (well sort of - it still look pretty much like Excel).
Now we want to increase our security by only allowing signed macros within our company.
So we created a certificate, signed our VBA AddIn macro code and installed the certificate. Actually two certificates, one as a trusted root certificate and one in the list of trusted publishers.
And now we want to change the settings in the Excel trust center, so that only signed macros are allowed to run. And this works very well with all of our Excel macros - except with the AddIn.
Here comes the tricky part.
The AddIn itself starts and runs. The AddIn checks if a special type of excel file (with a certain custom property) is opened and starts an initialization process. The excel file itself doesn't contain any macros (it's an *.xlsx), but it contains numerous buttons (shape objects) and those are "connected" by the initialization procedure to other procedures (subs/ macros) from the AddIn.
MyWorksheet.Shapes("ShapeName").OnAction = "AddInModuleName.ProcedureName"
This code attaches the VBA subs from the AddIn to the shapes (buttons) in the (macro free) worksheet. So the worksheet becomes wired and functional.
This works very well when no limitations are put on the macros. But in this case with only signed macros allowed to run, the code is not excuted. The buttons are dead.
The code itself is just fine. I can trigger it e.g. with a keyboard shortcut. But the button refuses to run the code.
My explanation for this is:
By changing the ".OnAction" property of the shape, this itself is regarded as code - at least from a security point of view. So you could argue that I dynamically add "macros" (the OnAction property) to an excel file. And this code is not regarded to be signed. It doesn't inherit the safety level from the code it created.
Whatever the reason my be. My buttons are not working, despite the fact that the code is signed and trusted.
Any ideas for workarounds (despite the fact that I could probably use the Excel ribbon instead of a self made interface)?
I got it.
I post the answer, because this may be interesting to others too.
This is the premise:
We have an *.xlsx file, in other words an excel file with no macros.
We have a digitally signed and installed add-in (and alle certificates properly installed).
But all shape objects (buttons) in this file contain references to macros, in this case references to an add-in. This references are stored in the "OnAction" property of each shape.
When Excel starts, it runs the security check before any code is executed (makes sense). Now Excel finds those strings in the "OnAction" property of the shapes and says: "Hm - that's suspicious! I better block all shapes." It doesn't block the macro code in the add-in or so - just the shapes (the triggers) themselves. And it presents a macro warning (with default security setting). This happens - even when there is no macro available. If the OnAction properties contains any string, Excel will block it.
In the meanwhile my digitally signed Add-In runs just fine in the background provided that all certificates were installed. But none of the buttons is able to trigger any code (keyboard shortcuts work just fine).
So Excel has no problems with my add-in. It just doesn't want those OnAction properties to contain any strings. This is kinda strange. If Excel doesn't allow macros in the file. Why does it allow OnAction properties. Those should also not be saved in an *.xlsx file.
And this is the workaround:
I added a BeforeSave event in my add-in clearing all OnAction properties of all shapes in my workbook. And an AfterSave event which adds all those strings again.
So the saved file is cleaned from all suspious code.
Excel opens the file.
The file passes the security check.
And AFTER that my add-in code runs and wires all shapes (writes the macro calls in the OnAction properties of all shapes) and
whoosh - all Buttons are fully functional.
So Excel has no problem with the shapes (in an *.xlsx file) calling add-in macro code.
Andn it has no problems if this code is added during runtime.
It just doesn't like those "calls" to be there during the security check at start.
Feels almost like hacking....
I created some Excel macros with VBA, saved it as .xlam file. I copied the file to another computer (running Excel2013) and put it in the following folder:
%UserProfile%\AppData\Roaming\Microsoft\AddIns
I enabled the Add-In from Excel > File > Options > Add-ins. Now I want to add those macros to Quick Access Toolbar(QAT). In the QAT options, I choose "Macros" from drop-down menu. The macros didn't show up as I had expected. The list is blank.
My subs do not have parameters if that matters. I have searched the forum and Google with no luck. What else I can check? Thank you!
I experimented with one of my own add-ins. All the subs in a general module were visible; however, none of the functions were. (Even the functions with no parameters -- tested by changing Sub to Function temporarily. The switch resulted in that macro disappearing from the macro list.)
Since you don't mention if there was this issue on the first computer; I am assuming that you would see the same thing there, if you checked.
If you sometimes need a return value from those macros, could you create "calling" macros? Subs which call those functions? If you never need a return value, I would recommend just changing the designation from Function to Sub on the relevant macros.
You could also check out this answer on how to add a button to the excel ribbon via add-in code. This could be useful if you plan on moving the add-in between multiple computers.
Foolish me!
I saved the macro module into personal.xlsb. However, I was trying to export it by creating a blank spreadsheet (e.g. "Book1.xlsx") and save it as Excel Add-In (e.g. "Book1.xlam"). Of course the Book1.xlam won't contain any macro!
I apologize for newbie mistake.
I am updating an Excel Spreadsheet from Office XP .xls to Excel 2010 .xlsm. When I did this, some of the function names were renamed or are not able to be accessed any more.
These are hundreds of functions on hundreds of module pages in my VBA editor. Is there some way to find the function I am looking for without opening each module and searching through it? It seems to me that find only works inside of each module page.
I still have the working xls and if I could just, for example, control click the function name and it would open up the module that contained that function, I would know where it was. Is something like that possible? Or is there a function finder?
Thanks!
(Everything below is related to the VB Editor)
Right-click on the function name, then chose "Definition" in the context menu.
For error checking, go to VBE menu "Debug" → "Compile <module-name>".
For structured overview of all the available methods, properties, events, objects, types, press [F2].
(For UDFs found in formulas of worksheets)
Keep the spreadsheet and the VBE open;
Copy the name of the UDF from the formula;
Paste it in the Object Browser [F2] in the search box; double click on the found UDF will open the containing module.
Unfortunately, I don't know a more straightforward way, but is better than manual search I think. :-)