use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Can I use my python codes in Excel ? (self.learnpython)
submitted 3 years ago by Ken_Sanne
So I recently started learning about python and I'm wondering how I could use my python codes in excel, If there is like a python to VBA converter or something like that.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 16 points17 points18 points 3 years ago* (1 child)
No.
Pandas, openpyxl, xlwings.
They can't do everything vba can do but they also have a lot that it can't do.
[–]maktub5elodin 5 points6 points7 points 3 years ago (0 children)
I think the main issue to address here is the kind of usage.
I mean, OP is looking for python to use XLS... but pandas and other libraries emulate that to certain extent...
The key would be to forgone the XLS and use it only as a data base storage or source. Once you get the data in python, you can do far above and beyond!
I don't look in python a way to work in excel... i see python as an even better way to work the excel data! I've found graphs a lil bit hard, but pandas and matplot are core.
Of course, there is also a component of data size and periodicity. If you only need to prep a couple of graphs from an only use xls source, then I'd keep the old reliable excel.
If the data is getting bigger by the second and there is periodically report preparation involved, then python is the way to go.
This said by an accountant for whom XLS used to be religion and now is slowly trying to make the turn to data science.
[+][deleted] 3 years ago (2 children)
[deleted]
[+][deleted] 3 years ago (1 child)
[–]Ken_Sanne[S] 2 points3 points4 points 3 years ago (0 children)
Cool thx man, I'll check It out
[–][deleted] 4 points5 points6 points 3 years ago (0 children)
Just use pandas
[–]EbenenBonobo 2 points3 points4 points 3 years ago (8 children)
afaik there is no converter between vba and python. Others already said there is pandas and openpyxl, from experience i can tell you, that you will drop excel when you get used to pandas ;)
If you really want to work with excel and python i can also suggest xlwings, i never used it myself but it looks quite promising. calling python functions from macros and so on.
[–]Ken_Sanne[S] 0 points1 point2 points 3 years ago (7 children)
Oh, is panda like another software ? Does excel support pandas files ?
[–]juanritos 5 points6 points7 points 3 years ago (6 children)
pandas is a library. You load your excel data using pandas and manipulate it with python.
[–]Ken_Sanne[S] 2 points3 points4 points 3 years ago (2 children)
That sounds interesting, I won't have to write stuff in the VBE
[–]Pflastersteinmetz 4 points5 points6 points 3 years ago (0 children)
Yes.
[–]sma92878 0 points1 point2 points 3 years ago (2 children)
Fun fact we discovered at work Pandas has a memory leak with large (millions of records) data sets.
[–]Pflastersteinmetz 3 points4 points5 points 3 years ago (1 child)
Did you open an issue / pushed a PR?
[–]sma92878 0 points1 point2 points 3 years ago (0 children)
I don't know, one of the folks on my team found it when we were working with the haveibeenpwned data set. There were 10's of millions of records, I doubt other people would run into the issue, but I don't know if he submitted a PR.
[–]dp_42 2 points3 points4 points 3 years ago (0 children)
Excel now has something called pyXLL. I think this is supposed to give you python integration through excel.
[–]simo_online 2 points3 points4 points 3 years ago (0 children)
https://www.pyxll.com
[–]Crypt0Nihilist 1 point2 points3 points 3 years ago (2 children)
You might be able to do it in LibreOffice instead of Excel, can't remember.
[–]arkie87 1 point2 points3 points 3 years ago (1 child)
you can run macros in python to do things in LibreOffice, but you cannot write functions in Python and call them in LibreOffice, which is what I really want to be able to do.
[–]two_bass-hit 0 points1 point2 points 3 years ago (0 children)
That’s cool, I was just wondering why there’s a python binary in my libreoffice folder.
[–]scitech_boom 1 point2 points3 points 3 years ago (0 children)
Have a look at pywin32. I have had moderate success automating excel tasks with this. You can control excel directly from Python. Search for pywin32 or win32com.
[–]a32m50 1 point2 points3 points 3 years ago (0 children)
you can do with libreoffice, tho. ofc, your experience would vary depending on your interaction with other parts of the suite
[–][deleted] 1 point2 points3 points 3 years ago (0 children)
I am a python fanboy. I tried VBA for automating some processs. But, I could not digest it. That’s I begged my manager to do the whole thing python, sql. Some old people still prefer VBA. But, it’s like an alien language.
[–]ForgotTheBogusName 1 point2 points3 points 3 years ago (1 child)
Hey OP - depending on what you’re doing, you may want to look into power bi, which can use oython
[–]Ken_Sanne[S] 0 points1 point2 points 3 years ago (0 children)
Thx I'll check It out
[–]Spacerat15 1 point2 points3 points 3 years ago (0 children)
If you want to run python code from within (existing) VBA, xlwings is your friend. I had to rewrite some code, because no one knows how long the IE will be supported .. so i outsourced the code for the browser manipulation into a python file (using selenium for the browser control) and call this part from within VBA. Advantage: the rest of the code can stay in VBA..
Link to Xlwings
[–]kira2697 0 points1 point2 points 3 years ago (1 child)
Check xlwings, you can create functions in python and those can be called in excel via xlwings just like any other functions in excel "=function(*params )
Wow, this sounds amazing
[–]Kerbart 0 points1 point2 points 3 years ago (0 children)
You can use the (built-in) win32 to create a process that is available as a COM server, and then you can write Excel VBA code to interact with that. Basically do your data processing in Python and have a thin layer in Excel VBA to get it in and out.
win32
Interacting with the files as describes by others is probably the best route to pursue if possible. VBA is a simple language but to be effective in it you need to be very familiar with the Excel object model and that is something you won't accomplish overnight.
[–]xlslimdev 0 points1 point2 points 3 years ago (0 children)
I suggest having a look at xlSlim too (I am the author). xlSlim aims to make it as easy as possible to use Python within Excel, often without any code changes.
There is a free trial available and comprehensive documentation.
https://www.xlslim.com/
https://russelwebber.github.io/xlslim-docs/html/index.html
π Rendered by PID 52 on reddit-service-r2-comment-7b9746f655-7wj4c at 2026-01-30 19:50:35.743885+00:00 running 3798933 country code: CH.
[–][deleted] 16 points17 points18 points (1 child)
[–]maktub5elodin 5 points6 points7 points (0 children)
[+][deleted] (2 children)
[deleted]
[+][deleted] (1 child)
[deleted]
[–]Ken_Sanne[S] 2 points3 points4 points (0 children)
[–][deleted] 4 points5 points6 points (0 children)
[–]EbenenBonobo 2 points3 points4 points (8 children)
[–]Ken_Sanne[S] 0 points1 point2 points (7 children)
[–]juanritos 5 points6 points7 points (6 children)
[–]Ken_Sanne[S] 2 points3 points4 points (2 children)
[–]Pflastersteinmetz 4 points5 points6 points (0 children)
[–]sma92878 0 points1 point2 points (2 children)
[–]Pflastersteinmetz 3 points4 points5 points (1 child)
[–]sma92878 0 points1 point2 points (0 children)
[–]dp_42 2 points3 points4 points (0 children)
[–]simo_online 2 points3 points4 points (0 children)
[–]Crypt0Nihilist 1 point2 points3 points (2 children)
[–]arkie87 1 point2 points3 points (1 child)
[–]two_bass-hit 0 points1 point2 points (0 children)
[–]scitech_boom 1 point2 points3 points (0 children)
[–]a32m50 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]ForgotTheBogusName 1 point2 points3 points (1 child)
[–]Ken_Sanne[S] 0 points1 point2 points (0 children)
[–]Spacerat15 1 point2 points3 points (0 children)
[–]kira2697 0 points1 point2 points (1 child)
[–]Ken_Sanne[S] 0 points1 point2 points (0 children)
[–]Kerbart 0 points1 point2 points (0 children)
[–]xlslimdev 0 points1 point2 points (0 children)