Force excel 2007 to open in automatic calculation mode by default - excel

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

Related

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.

VBA - How run a Macro from another workbook without opening it?

I wanted to save all my VBA Project in a Excel workbook (or other type of file if possible) and then embbed it to run in another workbook. I've seen topics about it but only found ways to run the macros opening the first sheet.
I want to run a macro from a first workbook in a second one without opening the first workbook to do it. How can I do that?
Save the file with the macros as a xlam file and Excel can load them each time Excel opens.
You need to open File -> options -> add-ins.
At the bottom there is a button Go to (or something, I don't have English Excel on the current computer.)
Then add the file to the list by clicking Browse and finding the file you just saved as xlam file.
Two scenarios comes to mind:
1) You have a second macro for personal use and can save it locally (save in: %USERPROFILE%\AppData\Roaming\Microsoft\Excel\XLSTART). This will allow you to create quick-buttons for your macros, etc. These types of macros open with Excel and will be separate VBA Projects inside of the default VBA editor.
2) You have a network or drive that multiple users need to access, so each user has a macro in their file (.xlsm or .xlsb), where that internal macro reads Application.Run "filepath\workbookname.xlsb!macro", which also allows you to call a private subroutine (note that you could use Call, but Application.Run will ensure that even Private macros are able to be accessed). This shouldn't require the other workbook be open, though I have personally had one user whose computer always opens the other file, regardless.
Edit:
Third scenario (really 2b):
3) You have files where you want to regularly access another file... you will follow a similar approach to point 2 where you make a macro to Application.Run, though you can save that macro in your XLSTART folder... this will allow you to have a source macro location where others may also want to access and utilize. The source document would allow you to maintain 1 file for many users.
Your answers were great! Great to know about XLSTART folder from #Cyril, but based on #Andreas answer I found my path.
The "problems" with adding an Add-In as #Andreas said, are cause my VBA Project would be avaliable on the VB Editor to every workbook on that computer, and to run my macros I'd have to use Application.Run("workbook.xlam!Macro").
Then I found References, which I have the same features, including I can delete my .xlam file to remove my code, and don't have the problems I mentioned above.
Adding my VBA .xlam file as an reference, it'll be avaliable only to that specific workbook and I can run my macro just like it was on the same workbook.
For general knowledge:
ADDING A REFERENCE:
1- Save your project as an Excel Add-In (.xlam file)
2- Open your target workbook, go to the Visual Basic Editor
3- Go to Tools > References > Browse... find your .xlam file and make sure it's checked.
4- Done! Now you'll see the project on the editor and can run your macros just like it was on the same workbook.

How to refer to Excel macros (not functions) in .XLAM addin saved outside Personal Macro folder in Excel 2016/2019?

We can create an .XLAM addin with custom functions (UDF). Once we connect Excel to the addin, these UDFs can then be called from another workbook regardless of where the addin was saved (even outside the Personal Macros folder).
But the same cannot be done for macros (sub-procedures) saved in the same .XLAM file. From my research and trial it seems the sub-procedures can be called correctly if the addin was saved in the Personal Macros folder. But if the addin was saved somewhere else, the macro would not show up in the Macro list upon pressing Alt-F8.
Is there a way around this? We need the addin to be saved in C:\OneDrive\Macros\Addin.xlam because the addin would update frequently so this saves the hassle when everybody updates it automatically via OneDrive.
We are using Excel 2016 and 2019.
After several weeks of researching and trying out different methods, I found the best method as follows:
Make sure you saved your macro source (e.g. MyMacros.xlsm) as MyMacros.xlam so that the add-in contains the latest macros and functions.
Make sure MyMacros.xlam add-in is connected in Click File - Options (Or Alt - F, T) Add-Ins - Manage Excel Add-Ins - Go (G)
In the second Excel file (let's say MyExcel.xlsm), open VBA Editor (Alt-F11). Choose the MyMacros.xlam project and rename the name to MyMacros to be different (pic) In my example pics MyMacros is FreelensiaMacros.
If you have several XL files open, click on the MyExcel project in the left VBA Project List pane (not MyMacros!). Then go to Tools - References and select MyMacros from the list.
You should now see a new reference in the VBA Project panel on the left side (pic)
5., Create a module named something like CallMyMacrosMod and type in several macro names from the MyMacros.xlam file using Application.Run such as:
Sub FormatTables()
Application.Run "MyMacros.FormatTables"
End Sub
It is convenient to construct texts in the MyMacros.xlsm file itself storing the commands to call all of your macros. You can then copy and paste to Word (to avoid the quotes problem), then copy from Word and paste in this VBA Editor.
Save and close the VBA window.
You can now call the MyMacros macros from the macro list of MyExcel file without having to kep MyMacros open, simply by typing Alt-F8.
Save and close your XL file.
Sources:
https://www.myonlinetraininghub.com/calling-vba-in-add-ins-from-vba-modules
If the add-in is loaded, you can call any sub/function with the following code
Sub: Application.Run "YourAddinSub",param1, param2, ...
Function: Application.Run("YourAddinFunction",param1, param2, ...)
If needed, you can qualify the sub. For example: YourAddin.YouAddinSub

Recovering datas from an Excel/ActiveX spreadsheet

I'm having the following issue: I've an Excel spreadsheet with a lot of VBA codes and ActiveX controls, including RExcel formulas.
The Excel version is 2007.
When I try to open this file, Task Manager says Excel isn't answering and something starts like if Excel started running endless codes; I deactivated each control and it still seems broken.
I would like to recover at least some formulas I've written in that spreadsheet, but this is actually impossible by opening the spreadsheet in conventional way.
Could you tell me how I can "read" formulas and text in that spreadsheet without opening it by Excel?
Thanks,
Indeed have calculation set to manual for a start.
Now set your security settings such that macros and activeX are disabled:
Excel Options > Trust Center > Trust Center Settings... > Macro Settings > Disable all macros with notification
For ActiveX I am not sure if there is a menu in excel-2007 like for macros, but if there is make sure it is set to not run as well.
Now you can open your excel workbook and it will not run your macro's and shouldn't auto calculate or update!
ADDED: I have had something like this in the past and this is what worked in 1 occasion: install an other office excel application, like open office (the calc application has the excel functionality) and see if it opens in that application. Then if it does, save the file (under another file name) and close it. Open the new file under MS Office Excel, and see what is still recoverable.
Good luck!
use a tool like 7zip to extract the files. the sheets/formulas are in the .xml
the code in a macro enabled spreadsheet is in a .bin file
this can be read with MalOfficeScanner

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