Search code examples
pythonexcelwin32com

How to F9 Excel book using Python?


I tried to adapt VBA examples from How do you get Excel to refresh data on sheet from within VBA?, they do not work: sheet.Calculate does nothing, other versions of calculate cannot be found...


Solution

  • Adding a CalculateFull macro progrmmatically and calling it solves the problem, but looks convolutive ...

    xlmodule = book.VBProject.VBComponents.Add(1) # http://support.microsoft.com/kb/282830 if this line throws an error
    xlmodule.CodeModule.AddFromString('Public Sub AnotherCalculateFull() \n\
                                                   Application.CalculateFull \n\
                                                   End Sub')