Calculate a closed workbook without opening it - openpyxl

I try to use xlwings and openpyxl to work on workbooks. I am just wondering if it is always mandatory to open a workbook to manipulate it.
For example, is it possible to recalculate a closed workbook without opening it?
I tried app_visible=False of xlwings, it seems that it still launched Excel, and then made it invisible.

No, it is not possible to recalculate a closed workbook without opening it.

Related

Excel 2013 Remove Broken Data Model

I created an ultra-simple dashboard-type tool using pivot tables and charts - the idea being, "keep it simple and it won't break." However, when I saved and closed the workbook and tried to open it again and refresh the data, I get these errors
Every time I try to do anything related to those pivots, that error message pops up. How can I fix or remove the data model in this workbook to make it usable again?

Way to capture double click to open file?

Is there a way to have an Excel macro to check what file I double clicked on to open.
When I open that file, the Add-Ins installed load first, then the file I clicked on loads. How can I write code inside one of my Add-Ins to check what the filename is that I am trying to open?
I tackled this by using 2 instances of Workbook_Open inside an excel Addin.
When a file is loaded, the addin starts up, and checks to see if there are any active workbooks. If there is none, then we wait a little bit and check again, looped as many times as you deem necessary, or until there is a valid workbook open. This makes sure your computer has time to load up the excel file. Once there is an active workbook, we process it to make sure it is not the workbook of the addin. If it is, then we exit our code. If it isn't then we Do Stuff.
I solved 2 of my questions on this site with the same code that can be found HERE
Note: I left out the parts where I Do Stuff... because really it's there to do anything you want with it. The code in the link just does what the previous paragraph describes.

Keep getting Excel and Windows Prompts while working with Interop Services

All of this is being done in VB.NET using the Excel 14.0 Interop Services
I am at my wits end. I keep getting prompts from windows and excel during the middle of a batch run.
The program i have takes in a workbook with batch records, then runs simulations on each batch record, then writes the results back out to the excel file.
The steps:
Open workbook
check to see if workbook is already in use by another program.
if it is in use. we try to close the workbook. then we wait for a set amount of time before trying again.
if the workbook is not in use we continue.
Get the contents
Mark the records as being processed
save and close the file.
process the records.
do the same process above to open the workbook.
save the results to the workbook.
close the workbook.
loop these processes until all the records have been simulated.
Ok the problems that can occur:
Workbook is already in use or two programs are trying to interact with the save workbook at the same time.
Ok now for the problem that i am having.
When the workbook is being interacted with by two programs at the same time. a prompt will show saying the file is currently in use.
another problem that happens that i can't explain is excel will show a prompt saying that the file is now ready to be modified with the options read-write, notify, cancel.
I need to find a way to handle these prompts programmatically.
If any one can point me in the right direction I would be very greatful.
You can prevent the prompts from appearing by setting:
Dim xlApp As Excel.Application = New Excel.Application
xlApp.DisplayEvents = False
But I've not found a way to actually "catch" the prompts and do something useful. I've noticed that often if Interop cannot get hold of a file then it will throw an exception. The exception rarely contains any way to distinguish what the actual error is, but you can sometimes work it out based on what could happen at that point.

Auto run good Macro before User Macro? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to protect cells in Excel but allow these to be modified by VBA script
any chance to run a specific marco [GodMarco] before any marco [UserMarco] which fired by user?
CASE I
I have a worksheet, which have lots button to do different action by user.
I have normal cells to let user input data, and have hidden cells to do the dirty work.
And since user may user [arrow] or [tab] to circle through, I have to protect the sheet.
And made them not selectable.
And now VBA stopped.
I know I can add vba codes to unprotect and protect again and again, but I think it is stupid to add them to each marco.
So can it be something like GODMODE that before each marco fired by user, run GODMARCO1, and after user marco, run GODMARCO2?
[DONE, THANK YOU.] CASE II
Or can we get some cells not selectable by user but selectable by VBA?
THANK YOU VERY MUCH.
Open the VBA window (Alt + F11). In the property window of the sheet you want to protect you will see the "ScrollArea" property which will limit the area that can be selected by the user, set it to whatever range you want to make accessible to your users.

Excel Automatic Calculation Setting

I have a complex project in `Microsoft Office Excel 2007' which utilises a large number of UDFs. Through VBA in a Workbook_Open Event, I set Excel Automatic calculation to OFF and a strategically placed Calculate method to manually calculate the cells whenever I need it so that the UDF doesn't perform recalculation unintentionally.
If the workbook is the ONLY one opened (or the first to open) in an Excel instance, everything works perfect. Only when it's opened AFTER another workbook (within the same instance), my project will inherit the Automatic calculation setting from the FIRST workbook and perform endless calculation on my UDFs. The disable code placed in the Workbook_Open event isn't executed until the UDF finishes the calculation (which can take forever). This only happens if my project is NOT the one opened first.
Through http://www.decisionmodels.com/calcsecretse.htm, I discover that it is the nature of Excel to perform the calculation process BEFORE the Workbook_Open event is executed.
So the question I have obviously relates to the project being opened AFTER another workbook is opened with automatic calculation turned ON:
How do I force my project to disable automatic calculation
without it performing recalculation first (remember, problem only
occurs when the project not the first one to be opened since it will
follow settings from previously opened workbook) OR...
How do I get the project to open in ANOTHER INSTANCE (when double clicked) to avoid
inheriting automatic calculation setting from the previous workbook.
Either way, the answer I'm seeking is for the project to open without performing the calculation first.
Thanks
One way is to use a different workbook (Opener.xls) to initiate opening the UDF workbook (udf.xls)
in Opener.xls the Workbook_Open code
- sets calculation to manual
- opens udf.xls
In your question I don't recognize the way you use to change and inherit that option to your workbooks, But I answer it as a solution:
Use VBA and running VBA macros to change that option for just your active sheet as soon as you need to calculate; by using it like this:
With ActiveSheet
.EnableCalculation = False
.EnableCalculation = True
.Calculate
End With
In another ways that may you need, you can read this part of MSDN article.