Python and Excel Add Ins - python

I have written a code which opens an excel file via excel wings library and instruct such file to run a macro within the excel file itself. The macro within the file consists of a series of Refreshes which happen on another excel workbook through some excel add ins.
The issue is that when I open the excel file and run the VBA macro from there no issues arise. However, when I use Python to run the process I get a run time error 1004 in the VBA macro, which reads macro not available in the current workbook, despite the macro obviously being there. I believe this is because, for some reason, when Python launches Excel the add ins may not automatically load.
I have long looked for a solution around but nothing satisfactory yet. Any help is massively appreciated!

Related

How to open an excel file in heroku?

I'm using heroku with streamlit to do excel automations. But I need to execute the excel formulas so I can get the values computed by them, and to do so I would need to open the excel file. As it is an RPA, I don't want to open the excel file myself, manually, I want the code to open it for me inside the system and execute the formulas, so the code opens the sheet with pandas or openpyxl and get the values provided by the formulas. As heroku runs on linux, OS is not an option. I've tried xlwings a long time ago and it did not work as well, but I'll study it and see if it works, but if you guys have some other recommendation for me, that works better than xlwings (or even something about xlwings usage), it would be really helpfull!
Thanks in advance!
I have already tried to use pandas and openpyxl data_only=True to get the values computed by formulas, but both only work once the excel file has been opened manually, executing all formulae. I want to simulate the manual opening of the excel file inside heroku, but without literally opening it, so formulas inside the file are executed.

Saving Excel files in Python to a OneDrive Directory and then error opening the file do it being used by Python

My Python code properly writes to Excel using the pandas pd.ExcelWriter function. The challenge I am having is that I am saving the file to a OneDrive directory and it won't let me open the file in Excel once the code is executed unless I close Python. Effectively, the Excel file is considered still be used by Python and therefore cannot get synced in OneDrive.
Any suggestions on how to deal with this?

Restoring previous version in Python

I am a py script that writes data into excel file. I am running the latter script on VM that sometimes crashes and if at that moment py script was writing data to excel, it corrupts the excel file.
Current solution to fix corrupt files is to manually 'Restore Previous Version' from file properties.
However I would like to do this task with python. Is there any solution for this?
You can save a copy of the excel file before manipulating it. If your script crashes because of an exception then you can catch it and then restore the file. If it crashes because of something like a memory error then you still have the copy of the file as a backup.

I have an excel workbook that automatically runs a macro when it is opened. Is there a way to pass parameters into this?

I'm currently writing a Python script that opens excel, runs a macro, and then saves it. Because I was having trouble with Openpyxl and XLWings calling specific macros, I decided to just automatically have the macro run when opening up excel. However, is there a way to pass in parameters from the Python script for the automatically-running macro to take?

Send ctrl+q to excel file using python

I have an excel file that I need to press ctrl+q to make a vba code(macro) to run.
is there a way to do this with python?
someting like:
with open (my_file,"wb")
"press ctrl+q"
close file
Thanks!
the open command is for opening a file and manipulating it's raw content - not suitable for your need
the are are modules for reading and writing excel files like openpyxl, but they don't include running vba macros. if the macro functionality can be implemented in python, this will probably be a good start.
If you need to run macros, you need to interact with an instance of excel using com automation (so you need to have it locally installed) - the pywinauto module can be a good start
I built a macro that starts when I open the file and add it to a template.
I created my new files with the template (using panda) and when I open them- the macro runs alone,
Thanks All!

Categories