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!
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?
I want to write a VBA macro in Excel to call a python script. The python script will execute some commands then return a pandas dataframe. I have code that writes to the excel spreadsheet and that is inside the python script.
I have installed xlwings and read through the VBA macro tutorial but am still confused. Should I use a User Defined Function? Do I need to "return anything" in the script?
If your Python script writes to the workbook directly, this is not difficult. First, you don't need to return anything from either the VBA macro or the Python if what you write to the workbook is sufficient for you.
You don't need a UDF. All you need is the following (which I've basically copied from the xlwings official docs here):
1) Make sure your excel book can talk to the file you have your script in (best done using the command xlwings quickstart <project_name> on the command line, then copying your script to the resulting Python file.
2) Make sure you can call everything you need from a single function like __main__() (or be prepared to run execfile or something similar)
3) Go to your excel book and make a command button, then assign it the macro SampleCall which xlwings has kindly provided for you
4) Now open the VBA editor. You should see the SampleCall macro immediately:
Sub SampleCall()
RunPython ("import testproj;testproj.world()")
End Sub
Just edit the names of testproj and world appropriately.
You can now click your CommandButton to execute your script!
I'm beginner in python programming and i'm currently struglling to find a solution with my python script. Here is my issue,
I wrote a small script in python using python-excel modules ( xlwt,xlrd and xlutils). This script is using an xls file that i converted from a xml data web file manualy by opening it and save it as a xls when i have done the local test.
But as i'm installing my script on a linux server side, i need to make this conversion automatically by using a python script but a i can't figure out how to do it ?
I looked over xlutils but i didn't find a way to make it.
By the way the purpose of this script is to compare 2 xls files and create a new update xls file.
Is it possible to do it with python ? or maybe directly on linux command tool?
Thanks
N.B: sorry for my poor english.
I am just at the very start of what I think is gonna be a long journey exploring the world of applications in Google App Engine using Python.
I have just downloaded Python 2.6.4 from the Python official website and installed it on my computer (I am using Windows XP). I also downloaded the App Engine Python software development kit (SDK) (from this page) and installed it, too. Both of these steps were suggested on the second page of Google App Engine's Getting-Started Guide.
However, when I moved on to the third page, which is titled as "Hello, World!", I ran into a sort of complication. It is written there:
"Create a directory named helloworld.
All files for this application reside
in this directory. Inside the
helloworld directory, create a file
named helloworld.py, and give it the
following contents..."
I am kind of puzzled here: How do I create a .py file? Is it like I need to create a notepad file (.txt) and name it helloworld.py (when I did so, it didn't change into any different file of any different, but rather stayed an ordinary .txt file) or should I somehow create that file using Google App Engine Launcher that I have installed?
When you downloaded and installed Python, you also installed IDLE. You can use this to easily write, run, debug and save .py files with syntax highlighting. To get started, just open IDLE, and select File -> New Window.
A .py file is a text file containing Python syntax. Use your favourite programming editor, or even NotePad.
Regarding your second problem, there's an option in Windows Explorer about hiding file extensions. Make sure it isn't checked -- you might well actually have renamed your file helloworld.py.txt but only seen helloworld.py
You will need a better editor than Notepad. With Notepad, use Save As..., and type "helloworld.py" in the dialog, including quotes so that the file extension is .py instead of .txt
I am kind of puzzled here: How do I create a .py file? Is it like I need to create a notepad file (.txt) and name it helloworld.py?
I'm not on windows, but thats how it works on other operating systems: Create a file with an editor, then save as ...
ps. and .py is the extension (like .docx, .bat, ...), but it's just a convention (although a highly recommended one) ..
pps. heard the http://www.e-texteditor.com/ has more capabilities than notepad ..
You have to be aware that the ending signifies recognition of files, not content. Name a file .py simply hints to the user (and the GUI) that it most likely is a python file.
That being said, python files are merely text files. You can simply create a text file with Notepad (or your editor of choice) and rename the ending to .py and work from there. Most modern editors will also highlight the syntax based on file endings.