Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a context manager to easily "freeze" excel when running code #254

Closed
sdementen opened this issue Oct 16, 2015 · 4 comments
Closed

add a context manager to easily "freeze" excel when running code #254

sdementen opened this issue Oct 16, 2015 · 4 comments
Milestone

Comments

@sdementen
Copy link
Contributor

It is often useful to freeze excel while running some code, freeze in the sense of disabling (=setting to False):

  • Application.ScreenUpdating
  • Application.EnableEvents
  • Application.DisplayAlerts
  • setting calculation mode to manual

A nice API would be a simple context_manager in the vein of:

with app.freeze(events=True, screen=True, alerts=True, calculation=True):
    ... do some expensive changes in a workbook ...

that would save the status of these variables, change them according to the flags, yield and then set back the variables back to their original status.

Any feedback on the API ? if ok, i'll do a PR for the Windows version (I have no experience nor access to a Mac)

@fzumstein
Copy link
Member

This seems like a good idea, and the API can still be discussed/fine tuned before the first release...

@zogzog
Copy link

zogzog commented Oct 12, 2017

app.interact could be slightly less confusing than app.freeze but I like the idea.

@sdementen
Copy link
Contributor Author

What about

with app.enable(events=False, screen=True, alerts=False, calculation=False):
    ... do some expensive changes in a workbook ...
    ... events, alerts and calculation are disable/frozen

We could also add the Application.Interactive attribute as app.interactive to come to for example:

with app.enable(calculation=True, interactive=False):
    ... do some expensive changes in a workbook ...

@fzumstein
Copy link
Member

implemented in #1671

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants