Excel - reference to XLAM file not being saved - excel

I can't get references to an XLAM file to be saved with a spreadsheet. I have to add the reference every time I open the spreadsheet.
Steps to reproduce:
Create a new workbook.
Go to the VBA editor and rename the VBA project to "MyAdvancedMath".
Add a module. Name it "AdvancedMath".
Add the following VBA in "AdvancedMath":
Option Explicit
Public Function Add(A As Double, B As Double) As Double
Add = A + B
End Function
Close the VBA editor. Save the file, changing the type to "Excel Add-in (*.xlam)". Let it save to the default folder ("C:\Users<>\AppData\Roaming\Microsoft\AddIns"). I called it "MyAdvMathAddIn.xlam".
Close all copies of Excel.
Start Excel. Create a new workbook. Save it as a macro-enabled workbook. I called it "MyAdvMathTest.xlsm".
Go to the VBA editor. Then go to Tools - References. Browse and add a reference to "MyAdvMathAddIn.xlam".
Set the formula in cell A1 to
=Add(4,8)
You should see the value 12 in cell A1.
Save "MyAdvMathTest.xlsm" and close it.
Open "MyAdvMathTest.xlsm". Cell A1 still has the value 12, as it should. Put the cursor in cell A1 and press Enter. Excel complains with a "#NAME?" error because it can't find the "Add" function.
Go to the VBA editor and re-add the reference.
Put the cursor in cell A1 and then press Enter. Now you see the value 12 again.
I'm running Microsoft 365 Apps for business, version 2209 (build 15629.20156 click-to-run). x64 version on x64 Windows 10.
The AddIns folder has been added to Trusted Locations. The Trust Center Macro Settings & ActiveX Settings are as permissive as they can possibly be, so it doesn't seem to be a security issue.
Note that the .xlam file must be referenced only from certain spreadsheets. Not all spreadsheets used by my employer.
Also note that this question was posted on Microsoft Answers (https://answers.microsoft.com/en-us/msoffice/forum/all/excel-reference-to-xlam-file-not-being-saved/f62b4764-1b27-4afb-a920-2e6804f8b213). The moderator suggested that I post here.
Thanks for any help you can provide.

Related

Adding macro from one excel sheet to another

I'm working with a list of addresses in excel 365. I want to perform a reverse geocode function to produce addresses from the available longitude and latitude info. to do this I have found an excel addin https://github.com/gramener/geocode-excel , which I downloaded. you can see an example in the screenshot above. the formula which it introduces is:
=#NominatimReverseGeocode(B32,C32)
Now what I want to do is make this available in my main sheet so that I can use the NominatimReverseGeocode. I've gone to File - Options - File - Add Ins
But the function 'NominatimReverseGeocode' does not show up in my main sheet. How can I make this function available in my main sheet?
EDIT:
I renamed the file to geocode.xlam in powershell. Now I'm getting:
If your intent is to make the Geocode functions available in all of your workbooks on your computer, do this:
Delete all previously saved Geocode.xlsm and Geocode.xlam files.
Download Geocode.xlsm.
Open it.
Go to File > Save As.
Change the file type from Excel Macro-Enabled Workbook (*.xlsm) to Excel Add-in (*xlam).
Click Save.
Close all instances of Excel.
Open Excel. (i.e. just the Excel application, so not opening a workbook.)
You should be on the Home screen.
Go to New > Blank workbook.
In the ribbon go to Developer > Excel Add-ins.
Check Geocode.
Click OK.
Close all instances of Excel.
Open any Excel workbook or make a new blank workbook.
Put =#NominatimReverseGeocode(51.5,-0.144) in any cell.
This should resolve to the Buckingham Palace Garden.
If your intent is to just have the geocode functions in one specific workbook, let me know and I'll write up the steps for that.
If you only need this code available for yourself and not other users by far the simplest way would be to create a personal macro workbook.
Create a workbook and save it as
C:\Users\username\AppData\Roaming\Microsoft\Excel\XLSTART\PERSONAL.xlsm
Copy the code from the GeoCode workbook into PERSONAL.xlsm.
PERSONAL.xlsm will autoload with Excel. Prefix your function call with the workbook name: =PERSONAL.xlsm!#NominatimReverseGeocode(B32,C32)

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.

Excel and self generating purchase order numbers

I'm trying to figure out if it's possible to create a formula that creates a new purchase order number every time I open up my purchase order form on excel. The current cell the number goes into is E5.
My hope is that by doing this it will eliminate duplicate numbers. They would start at 0100 starting in January.
I've searched the web for an answer but haven't found one.
Can anyone here help me?
Thanks!!!
So Using VBA, You can easily update the value of a cell when ever the excel sheet is opened.
Given your order number in row E5 this is the code you would add to the workbook
Private Sub Workbook_Open()
Cells(5, 5).Value = Cells(5, 5).Value + 1
End Sub
This piece will always update your cell value and add 1 to it whenever you open your excel sheet.
There are a couple of steps that you need to follow to get the code in your excel. Depending on your version of excel, first you will have to enable developer mode on your excel workbook you can do that by following instructions here.
Click the Microsoft Office Button Office button image, and then click Excel Options. Click Popular, and then select the Show Developer tab in the Ribbon check box.
Once you have developer mode enabled, you should be able to see a developer tab in the ribbons, click on the developer tab and then in the developer ribbon, you should be able to see the editor option, click on editor.
once you have clicked on editor, you would see a list of options in a small window, double click on "This Workbook" there. An editor window will open, and you need to copy and paste the code I have mentioned above there.
Finally save the excel sheet as xlsm (Macro Enabled sheet). And you should be all set.

Force excel 2007 to open in automatic calculation mode by default

I am working with excel application(AddIn) in excel/c#, getting a circular reference error which disappears when I enable automatic recalculation through excel options.
But I want to set Automatic option as default when the file opens, but for some reason it wont let me just save the .xlsx file as automatic option enabled. I found some articles stating that you have to have a personal.xlsx file in your XLStart folder with the desired settings which is used by other sheets as reference, which I created and all my local excel sheets works fine with automatic option by default except this one template (template.xlsx). The template is used to populate data and it has 29 sheets in it. So I don't know if that's creating the problem.
So now when I open excel, it opens the personal.xlsx first which has Automatic option enabled, but then, when the template.xlsx opens the option changes to "manual". Then I have to manually change it to Automatic option every single time. But all other .xlsx files in my PC opens in Automatic option by default.
How to fix this?
As I found in MSDN :
The user can select the mode through the Excel menu system, or programmatically using VBA, COM, or the C API.
1) You can change the option for a specific range by this:
Just with VBA:
Range.Calculate (introduced in Excel 2000, changed in Excel 2007)
and
Range.CalculateRowMajorOrder (introduced in Excel 2007)
2) Change option for Active Worksheet
By Keystroke: : SHIFT + F9
--VBA:--
ActiveSheet.Calculate
--C API:--
xlcCalculateDocument
3) Change option for All Open Workbooks
By Keystroke: F9
--VBA:--
Application.Calculate
--C API:--
xlcCalculateNow
For More read this MSDN article

How can I permanently prevent Excel from setting all new documents to R1C1 mode?

Every time I create a new excel sheet, I have to go in and change it's cell reference mode to the familiar A1, B1, etc. I can't seem to find a way to permanently set it to A1 style.
Is there a macro I can write or a way to use templates or something, so that I don't have to keep changing the R1C1 setting?
In Office 2007, Click the Office button and click Excel Options which you will find at the end near Exit Excel.
Go to Formulas tab and under Working with formulas, Check or uncheck R1C1 reference style to use it or to change it to A1 reference style.
(source: lytebyte.com)
If it doesn't stick you have some problem with a personal.xls or the default template or something I guess...
EDIT:
Try this first:
Close all spreadsheets down. Assuming you have created one previously, unhide your Personal.xls workbook (Window>Unhide; In Excel 2007 and newer,View,Unhide) and then uncheck the R1C1 reference style. Save your Personal.xls, rehide & close down Excel (clicking Yes to save changes to Personal.xls). With any luck you should now have your default A1 style back. You will have to repeat the above with any other workbooks in your XLSTART directory and/or the start up location in Tools>Options>General tab.
Then this:
Help > Detect & Repair.
If no good, try http://support.microsoft.com/kb/291288
Last resort:
Use Start > Run excel /regserver
NOTE the space after "excel"
You could create a toolbar button that allows you to change the worksheet to A1 type referencing. This Excel macro will do the job:
Sub useA1references ()
Application.ReferenceStyle = xlA1
End Sub
If that works, you can set the macro to run whenever you open Excel or create a new workbook.
In my case,
only this link worked (i paste the answer here, as it might go away):
Press [Alt]+[F11] to launch the VBE.
If the Immediate window isn't visible, press [Ctrl]+g.
In the Immediate window, type ? application.StartupPath and press Enter. VBA will display the path to XLStart.
Make a note of the response. Mine is
C:\Users\Bernard\AppData\Roaming\Microsoft\Excel\XLSTART
Open a new workbook
Open Excel > File > Options > Formulas > Uncheck ‘ R1C1 reference
style’ under Working with style > click on ‘OK’.
Click on File > Save as > Browse to the XLSTART folder and give the
file the name Book.xltx. Press OK
The biggest problem of the R1C1 reference style setting is that Excel saves it in templates and/or files. This behavior is unpredictable and differs from version to version. Due to this, sometimes, this setting gets spread like a worm from a single file.
To address the issue, I've written a small Add-In that silently forces A1 reference style for all existing and new workbooks. It contains also a macro requested and is tested on Office 2016 and 2019.
It's also worth mentioning that Office ADMX templates have a built-in policy to control R1C1 defaults (User Policies/Administrative Templates/Microsoft Excel 2016/Excel Options/Formulas/R1C1 reference style). It doesn't affect existing files and templates at all, though.
I suppose the template has been saved with the R1C1 option. Maybe you can open it, change the option and overwrite the original template?
As In.Spite mentioned, it's probably a default template issue. If you overwrite the default with one that has the R1C1 reference box unchecked, it should remember the setting.
Here's as KB describing where you can find the default template:
http://support.microsoft.com/kb/924460
Locate the template, open it, untick the `R1C1 reference box, and overwrite the old template.
Not directly applicable, but...
For some of my purposes R1C1 notation is very useful, so I made a macro that toggles it and attached it to a toolbar button:
With Application
If .ReferenceStyle = xlA1 Then
.ReferenceStyle = xlR1C1
Else
.ReferenceStyle = xlA1
End If
End With ' Application
I have written an add-in to address this (and related) issues w.r.t. R1C1 addressing. The add-in can be configured to save all workbooks in a specific format (either R1C1 or A1 mode) and also to force your Excel into the desired addressing mode whenever you open a workbook. It also provides a button on the ribbon to switch between addressing modes. It's available from: http://rath.ca/Misc/VBA/Excel/RC_A1_Toggle_v2.zip

Resources