I am using Excel 2013 and we are coming across random Excel files set to manual calculations and they do not seem to go away after resetting to automatic.
Those files seem to stay as automatic, but on a random day a different Excel file or the same Excel reverts back to manual. I want to auto execute a macro when loading any Excel file or just the program to set Excel to automatic calculations.
I tried the following macro:
Private Sub Auto_Open()
Application.Calculation = xlCalculationAutomatic
I received the following error message upon loading Excel:
"Run-time error '1004': Method 'Calculation' of object'_Application'failed
Troubleshoot:
An Auto_Open macro runs before any other workbooks open. Therefore, if you record actions that you want Excel to perform on the default Book1 workbook or on a workbook that is loaded from the XLStart folder, the Auto_Open macro will fail when you restart Excel, because the macro runs before the default and startup workbooks open.
If you encounter these limitations, instead of recording an Auto_Open macro, you must create a VBA procedure for the Open event as described in the next section of this article.
Question: is there a way to create a macro to reset any Excel file back to Automatic? I stored the macro in my personal workbook as I am hoping that the macro will execute on any Excel file I load.
I tried what you wrote and it works.
Just in case, here is my code :)
Private Sub auto_open()
Application.Calculation = xlAutomatic
End Sub
Related
I wrote a macro that does some calculations based on a particular type of excel sheet. Im trying to distribute this to my coworkers but the addition of a macro to a workbook and then running the macro is something foreign to them. I'd like to have a "shortcut" or some VBS program to open a specific workbook (specified by the user), run the macro, and display the results.
Your help is appreciated!
--Edit--
I wrote a macro in VBA. I exported the file to my desktop. Its simply called "Macro1". We have a standard form of excel sheet our company uses. Its literally the same sheet with different numbers. The macro I designed works on these kinds of sheets and does calculations. My coworkers aren't good with macros, so I want some sort of "code" that will prompt one of my coworkers for an excel file, then execute the macro on the file. Hopefully this clarifies any questions.
You need to make it a excel add-in.
Then in the add-in make it run on workbook open with Sub App_SheetActivate(ByVal Sh As Object) in thisworkbook.
In the macro you can then have it only activate on certain workbook name or workbook type by:
If range("A1").value = "something" ' something that makes the workbook type special.
' Maybe you need B1 value and so on too.
Do you need a way to self-install the add in just let me know and I have a code for that too.
Self install:
' if add-in is not installed and the workbook is a add-in (workbookcount =0)
' Also take note that this code will only run if the add-in is not installed
If Dir(Application.UserLibraryPath & "YourWorkbookName.xlam") = "" And Workbooks.Count = 0 Then
'optional ask user if he wants to install or not. Code not included.
' copy file from current position to add-ins folder.
Result = apiCopyFile(ThisWorkbook.FullName, Application.UserLibraryPath & "YourWorkbookName.xlam", False)
' activate the add-in
AddIns("YourAdd-inName").Installed = True
msgbox("add-in installed")
' Close Excel since add-ins does not work without restart of Excel
On Error Resume Next
Application.Interactive = False
AppActivate "Microsoft Excel"
Application.Quit
Exit Sub
End If
Note that the file must be saved as a add-in. (xlam) this means there is no sheets, the workbook is VBA code only.
Normally, that does not mean the code needs to be written in a special way.
Usually Range("XX").value works, but some commands may need to point towards the correct workbook. (you have two workbooks open with add-ins, the add-in with the code and the workbook with the sheets and numbers)
Hope this helps
I have a personal workbook macro written in excel vba... I want that macro run automatically as soon as a particular named excel file is opened by any user. And that it should not run if it is already been run on that excel file earlier..
Open excel vba editor: Shift+F11. In MsExcelObjects doubleclick on "This Workbook".On the right side write this code and adapt it to your needs:
Private Sub Workbook_Open()
If SheetX.cells(x,y) = 0 then 'adapt SheetX and cell(x,y) to your needs.
'execute your code here
SheetX.cells(x,y)=1 'placeing an indicator if program runs, so it wont run another time it starts.
end if
end sub
Hi I am using Excel to fetch live data from web into an Excel sheet and pushing it into a SQL Server Database using macro. The macro code is executing manually. The Excel sheet data gets refreshed every minute. I have to run this macro when the data gets refreshed from the web into the sheet. Can somebody please help me to understand how to do this?
how about stopping auto refresh from web and put it as part of the macro?
or try adding the macro for worksheet change, explained here - How to run a macro when certain cells change in Excel
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Call MyOtherSub
Application.EnableEvents = True
End Sub
You can drop this in the worksheet module for the sheet being changed. Note the .EnableEvents statements - these are very important in ensuring you don't wind up in an infinite loop if your called procedure changes something.
I have a VBA macro that makes prompts the user to save the changes to the Personal Macro Workbook each time it is run. Is there any way to disable this message?
I have tried this: ThisWorkBook.close SaveChanges:=Falsebut it still prompts the message
If there are no changes made to the Personal Macro Workbook, or if you don't want changes to be made, just use ThisWorkbook.Saved = True. You can also try setting Application.DisplayAlerts to False, call a close to the workbook, and turn the DisplayAlerts to True again.
The above can be seen here.
If you have formulas in a worksheet in the personal macro workbook, Excel will automatically recalculate them every time the workbook is opened and this constitutes a change which Excel will ask you to save.
Get round it by not putting formulas in the worksheets in the personal macro workbook. If your macro requires formulas, you could always create these in another workbook which your macro can access when it runs.
I encountered a strange error in an Excel 2007 add-in that seems to be reproducible with a few lines of macro code (Update: even without code, see below).
Open a new workbook and add the following code to the first worksheet.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.DisplayAlerts = False ' Suppress macro and overwrite warnings
ActiveWorkbook.SaveAs "test.xml", XlFileFormat.xlXMLSpreadsheet
End Sub
Now each change will save the workbook as an XML spreadsheet file.
However, when I open a second instance of Excel and copy a single cell from there to the auto-saving workbook Excel 2007 crashes. (I have also seen an RPC_E_SERVERFAULT error in a comparable situation.) In Excel 2010 the file is saved as expected.
Any ideas what might be the root cause for this behaviour and how to avoid it?
UPDATE
Seems like it's even worse: If I copy data from one Excel (2007) instance to another and save the target workbook as XML spreadsheet Excel crashes. I tried this on two machines, so is this a known bug?