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. :-)
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.
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.
This is it. I am trying to get the list of built-in functions of Excel (not built-in functions of VBA) by using VBA.
I know how to retrieve UDFs and functions in non-protected XLA and XLL addins, but I can't find a way of getting the list of excel functions. Do you know how I could obtain that using VBA? I think it should be a way.
I would like to avoid using list of functions copied from some site (or ms help), because that would ask the user to check it, in a regular basis, to keep it updated, which is not an option.
BTW, the context of this is a kind of parser of excel formulas to vba, which I have almost finished; I only miss this.
Thank you!
This is a partial answer. It only displays worksheet functions installed with your version of Excel.
Open the VBA window
Click View > Object Browser
Scroll down the Classes pane and click on WorksheetFunction
The list of functions will be displayed in the Members pane
Another open issue is how to transfer the displayed list of members into a worksheet column.
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".
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.