Python for VBA Developers in 30 Minutes

Поделиться
HTML-код
  • Опубликовано: 28 янв 2025

Комментарии • 99

  • @Excelmacromastery
    @Excelmacromastery  Месяц назад +13

    Let me know in the comments if you find this content useful

  • @laszlofodor6630
    @laszlofodor6630 Месяц назад +2

    I've been searching for reviews to see the differences between these two languages for a while. I finally found it. I like watching your videos, webinars, because they're always very compact, clear, understable and they have a lots of useful examples, best practices. Thank you!

  • @heljodedor5913
    @heljodedor5913 Месяц назад +6

    It is not only useful but extraordinarily explained. Thanks

  • @mrashid229
    @mrashid229 Месяц назад +2

    Thank you, Paul! I feel very happy that you are covering Python now. Possibly this is your third video on Python+VBA.
    Despite VBA having limitations, I think I need both Python and VBA side by side. To quickly develop UI and to take advantage of excel resources VBA surely is a good option and of course having Python in the middle resembling to 3 tier architecture.
    Combination of Python, VBA and Excel can be very promising, I think. Would you make more tutorials and courses on Python+VBA in coming days? What is unique about your tutorials is, you emphasize on efficiency, cleanliness and reusability of codes. Best wishes!

  • @wmcnabb
    @wmcnabb Месяц назад +2

    Paul, you never cease to amaze me with your video explanations. Have an awesome Christmas season and all the best in the new year.

  • @tunggf
    @tunggf Месяц назад +4

    Long time stick to the VBA and really hesitate to move to Python, this video is very useful for me. Thank you!

    • @Excelmacromastery
      @Excelmacromastery  Месяц назад +1

      Glad it was helpful!

    • @teaman7v
      @teaman7v Месяц назад +1

      Once you make the move and become comfortable you'll wonder why you didn't do it years ago

  • @StillChrist
    @StillChrist Месяц назад +1

    Spot on analysis as usual!
    My last project with VBA had me pending some time to expand the usefulness of the VBA editor by 1) turning the immediate window into a command line, and 2) taking control of the code editor to improve searching through the code base (over many modules) and ability to add snippets.
    The first takes advantage of the way the immediate window will execute one line of legit code per each time you hit ENTER. This includes, especially, the name of any function, including whatever parameters you want. This allows you to make menus and sub menus list out and then any ENTER anywhere in the line of code will execute the line, but not the next line. You can have menus just for help searching, and taking your cursor to, the most frequently visited parts of code no matter how separated they are among the modules. This is especially useful because of the way a lack of cold folding really spreads code out physically, and as the function drop down lists get longer, they too get harder to navigate.
    Send Keys in combo with API calls to the clipboard gives you 100% programmatic control over the code editor. You have to be careful though because you won't be able to use the Undo button if anything goes wrong. But it will let you insert snippets from a menu in your immediate window to where your cursor was last located in the code. This all depends on a hack around the peculiarities of the clipboard where an extra little Send Keys is needed and not likely to be discovered except by sheer determination and lots of experimentation.
    Also, by using classes, you can exploit the way the editor will drop down a pick list of available options in its intelligence when you type a period after a recognized key word (also enums). This can be exploited to enhance the command line conversion, functioning kind of like a drop down menu.
    Lastly, I used a combo of Open Workbook functionality, Send Keys, and AutoIt (script) to open Excel to the exact working environment I wanted to see, with the immediate window open with a familiar menu written on it, and the exact code pane (among many modules) open, with the cursor at the last location of code I was working on.
    This was a project in and of itself. Someone would do well to offer a package of some sort that helps people start their VBA projects this way. Maybe it could be made even better by showing how to extend and/or simplify with Python. But what I've described ought to be some kind of package that can be purchased. Any sale would need to include the caveat that messing with the clipboard and Send Keys might mess with the Num Lock key in a weird way, and who knows what else, which may require turning off and on the computer to clear. Also programmatically switching cursor between code pane and immediate window pane has to be done very carefully to avoid cross contamination. Anyone who can figure this out and make it simple should be paid well.
    In the end, I wasn't using cells for anything except the final display of whatever calculations were going on. Instead it was all file in and out operations. Better to use a comma delimited string, and string manipulation than cell manipulation. But dictionaries and collections were still a bonus.
    Lastly it's worth mentioning AutoIt as a VBA alternative similar to the way Python has become an alternative, or a nice supplement. AutoIt started as a better GUI (windows) control language that wrapped pretty much the entire windows API in a VB-like language. It has grown up around the Scite, open source editor mainly, but other editors are useful too. And the community has grown to add editor functionality and code base libraries of easily include-able code including in the form of snippet libraries. And you don't get bogged down with type casting at all as the compiler handles so much more of that than even VBA. It's easy to turn a typical variable (everything is pretty much a Variant) into an array, and to turn arrays into strings and write them into files. And easy to resize, reuse an array. AutoIt offers quite a bit of control within Excel as well. So if you just need to display the product of calculations that's easy to do. AutoIt too, only has one kind of function where you can choose to return a value or not. And like VBA, one way to return a value is through a ByRef in the parameters.

    • @Excelmacromastery
      @Excelmacromastery  Месяц назад +2

      Thanks for sharing. Very interesting to read - you really bent the VBA editor to your will.

    • @StillChrist
      @StillChrist Месяц назад

      ​​​​​​​​​​​​@@Excelmacromastery Yes indeed although it helps that the VBA "Immediate Window" is not a typical debug dump for the compiler, for error messages, ect. In fact the compiler won't ever dump anything at all to the Immediate pane, but instead uses message pop up boxes, or some colorations in the code pane.
      Anything that prints to the Immediate is invoked by the programmer. Even though it comes in handy for debugging, it can also be exploited as formatted output. That is, whatever format you can impose upon any text file that you might write out to, you can also impose the same on the Immediate. It is, after all, the same "Print" statement. In most cases I would rather read program out put that way than in cells. It just can't chart. It gives 100 lines of output before the top lines start to scroll away into the netherworld.
      So, because the Immediate is also sensitive to commands (the name of any function) and even intellisence, it functions a lot like interactive Python development environments for both command and formatted output. It, that environment , all belongs to the programmer, and not at all to the compiler error dump, or any other kind of compiler messaging. It's basically a "console" which includes the code pane within its programmatic ambit. Because of that, a really clever developer could ramshackle together a very basic version of a code versioning program.
      This is in case MS doesn't do any more development for another 20 years.
      Indeed, the developer of Python, Guido, may have worked for Microsoft and might even have worked on/in VBA...and hence, may have borrowed this idea when promoting Python. This interactivity really made Python popular, for example, when you could type in Print 2 + 2 into the "editor" and get 4 back, similar to how Gates and Allen typed Print 2 + 2 into the first demo of Basic for the MITS Altaire.
      Try Print(2+2) in the Immediate Window ;)

  • @maurocsgrnd
    @maurocsgrnd Месяц назад +3

    I like the idea of using Python along with VBA! Count me in if you ever develop a course on it. Now we have Python within a cell in Excel, and managing automation using VBA and Python together would be awesome 👌

  • @k0023382
    @k0023382 Месяц назад +1

    This is brillinat, I think this is the way to go in your channel, combining VBA with Python, and getting the best of both worlds. I just wonder if you can call an python script within VBA, threfore within Excel you might combine both.

  • @jorgealfredocarvalho
    @jorgealfredocarvalho Месяц назад +2

    Very intresting video. And, as usual, a very professional work.
    Best regards from Portugal

  • @LeviBailey
    @LeviBailey Месяц назад

    Outstanding video! Well chosen topics, very clearly and succinctly explained. It will be useful to many people - wish I'd had it a few years ago.

  • @joaocustodio2094
    @joaocustodio2094 Месяц назад

    Paul, thank you very much for another very useful and clarifying video.

  • @seamushand8439
    @seamushand8439 Месяц назад

    Thanks Paul Python has intimidated me for quite a while but i might give it a go again now. Thanks for this video

  • @richardbaron7106
    @richardbaron7106 Месяц назад

    The SecOps team in my company has a habit of disabling VBA every so often without any notification, which is no good when running power automate desktop flows. So after using Send Keys and Office Scripts in one flow instead of VBA for the past year, I've been thinking about using python to completely automate a couple of tasks on a schedule instead. Great video and useful information!

  • @iincitr
    @iincitr Месяц назад +1

    This video is amazing. I liked it very much and thank you so much. Best explanation for VBA programmers. But I wonder how we handle Python inside Excel with userform.

    • @Excelmacromastery
      @Excelmacromastery  Месяц назад +1

      You can create a GUI with Python. Then have it call code that interacts with Excel.

  • @YanYarman
    @YanYarman Месяц назад +3

    Excel has Userforms with control elements. You can make light office applications, work with databases via ADO. In Python, it's all much more difficult

    • @Excelmacromastery
      @Excelmacromastery  Месяц назад +6

      I plan to create a GUI application in Python soon so it will be interesting to compare with VBA.

    • @mrashid229
      @mrashid229 Месяц назад

      @@Excelmacromastery will love to watch that!

  • @peterlilley6819
    @peterlilley6819 Месяц назад

    Excellent video Paul, Yes there are some real wins there. Like anything this comes down to purpose. I use a lot of user forms as I generally write complex programs and need to guide the end user. I’d really like to know more about that side of things. Not all large organisations have Python available on their networks, having vba everywhere is a real bonus. I still have a question mark over speed, e.g. to read a range into an array is super quick in VBA.

    • @Excelmacromastery
      @Excelmacromastery  Месяц назад +1

      Thanks for the feedback. There are definitely considerations for using both.

  • @freeliberalminds
    @freeliberalminds 20 дней назад

    i loved this topic subject. Thanks so much Paul Kelly

  • @paul46722
    @paul46722 Месяц назад

    Very clear. Pandas iloc and loc now make sense to me. Cheers!

  • @rayearth9760
    @rayearth9760 Месяц назад +1

    I would like to learn more about Python form you. Based on simple code examples I'd like to know how to utilize Python for automation on schedul, on demand or when certain conditions are met (like workbook file present in location).

  • @guysamson1620
    @guysamson1620 Месяц назад

    Hallo Paul, amazing yr work is not only professional, but really easy to degest the knowledge y teach. As french natural speaker i love yr pronociation and can follow yr thoughs for better understanding. I'm really greatfull! I wish y and yr familie a wunderfull chrisma and a successfull and happy new year. Sincerly best regards. Samson

    • @Excelmacromastery
      @Excelmacromastery  Месяц назад

      Thanks Samson. Have a great Christmas with your family.

  • @hadibq
    @hadibq Месяц назад

    Thanks, Paul, for this video. Very useful indeed 👍👍

  • @muhammadkausar2842
    @muhammadkausar2842 Месяц назад +4

    I know python is powerful. But VBA language is very clear and easy to understand. We clearly know where if condition is end, where function or sub procedure is end. As my first language is VBA. So I think VBA is so easy. I also create powerful application and games using VBA code in Excel. Games like Tic tac toe, Date picker, calculator, custom ListBox and much more

    • @Excelmacromastery
      @Excelmacromastery  Месяц назад +7

      It's probably because you are so familiar with VBA. When you us python for a while you will find it readable too.

    • @teaman7v
      @teaman7v Месяц назад +3

      That's a matter of familiarity, rather than readability. This applies to any language. It doesn't take long for those issues to disappear.

    • @dketchel1
      @dketchel1 Месяц назад

      VBA was my first as well. Now that I’m using Python, I see VBA as outdated and avoid it if I can. Python can do what VBA does but with 60 to 80 percent less code. ChatGPT has helped a ton with learning how Python works.

    • @andrewcrisp8567
      @andrewcrisp8567 Месяц назад +1

      As somebody who has used VBA since the late 90’s I understand the advantages of familiarity. That said, for various reasons I had to learn Python, and have essentially stopped writing stuff in VBA totally. Once you have wrapped your head around the way Python works it is a substantially more capable language, with many built in capabilities that involve either messy or complex VBA code to achieve. Most of those features have not really been covered in this video (not a criticism, I can’t think of a way to explain it myself in a reasonable time) but Python is a far more capable, particularly in data manipulation and validation.
      The problems of dynamic typing are easily manageable with ‘Type Hinting’ and a decent IDE.

    • @Hallstrom007
      @Hallstrom007 Месяц назад +1

      Fellow excel nerd! So cool you are making games in Excel!

  • @hammeedabdo.82
    @hammeedabdo.82 Месяц назад

    Thanks, we need more videos like this.

  • @matthewbradley9430
    @matthewbradley9430 Месяц назад

    Enjoyed watching your video. I’d be interested to know your thoughts on when to use python and when to use power query?

  • @joaquintorrens3057
    @joaquintorrens3057 Месяц назад

    I personally use a vba function, calling an api.
    And on the same machine, an api server (fastapi) via python3.
    This is by far the fastest and best way i found to talk between excel and python3 on real time.

  • @gsr4535
    @gsr4535 Месяц назад

    Yes I do! I would like to find employment utilizing my VBA Access and Excel experience but finding it increasingly difficult. Python may help me. It doesn't seem too difficult.

  • @MattzRD42
    @MattzRD42 Месяц назад

    Thanks for that very usefull video. I've been thinking about learning a little Python for some time. I use Rubberduck, however, and I've mastered VBA so well that I can't really imagine which of my projects wouldn't be possible with it. Cross-platform is an issue because it obviously doesn't work with VBA. If only the day had a few more hours 🙂

  • @mathijs9365
    @mathijs9365 Месяц назад

    Very usefull
    Thanks!

  • @bengteriksson6619
    @bengteriksson6619 23 дня назад

    I found your Python and Panda presentation very useful and very nicely crafted at that. What I didn't find is how to deal with user forms. Can that also be done from Python?

    • @Excelmacromastery
      @Excelmacromastery  22 дня назад

      You can create gui applications. There are multiple ways to do it, such as using tkinter.

  • @hammeedabdo.82
    @hammeedabdo.82 Месяц назад

    I have heard that Python can be used to build applications in Excel.
    My question:
    Is it possible to build the same trading simulator application, which you built previously using VBA, in Excel using Python alone?
    And do you think building it with Python would be easier than using VBA, or the opposite?

    • @Excelmacromastery
      @Excelmacromastery  Месяц назад

      It's possible

    • @hammeedabdo.82
      @hammeedabdo.82 Месяц назад

      @@Excelmacromastery do you think building it with Python would be easier than using VBA, or the opposite?

  • @Nishun22
    @Nishun22 Месяц назад

    Do you have a course on Python for Excel?

  • @excelsocallmaster
    @excelsocallmaster Месяц назад

    With python now embedded Excel natively for all M365 customers, to switch from vba to python is going to get easier for users to make that jump, especially given all the machine learning, data science methods and of course the better graphs now available it is taking excel into the 21st century especially given VBA can’t be run on the web and office script as been a poor substitute with very little uptake within excel community fan base

  • @merazmamun4261
    @merazmamun4261 Месяц назад

    Did you hear about New Outlook and how it has no COM support? This is going to be a big issue as some of my macros use Excel to create and save Outlook emails.
    Is there any way to have Excel communicate with Outlook without using any 3rd party tools?

  • @amoleshchandrapaul4934
    @amoleshchandrapaul4934 Месяц назад

    Thanks

  • @luisgentil
    @luisgentil Месяц назад

    I was one who switched (mostly) from VBA to Python. My takeaways:
    - VBA remains the most accessible and distributable tool
    - Depending on your workload, VBA can be painfully slow. Even though Python isn't notable for performance compared to other languages, it has optimizations built in that can turn hours into seconds
    - Getting the hang of Pandas turned most of my Excel work obsolete. Past the learning curve, it's incredibly fast and straightforward
    - Eventually you need to gather data outside Excel. Python covers any scenario imaginable. If your process relies on daily copy/paste work, it's something to consider.
    - Python syntax is intuitive and significantly reduces development time and stress

  • @Dexter101x
    @Dexter101x Месяц назад

    I would love to learn how to use Python within Excel. I know how to bring up the Python command line, but don't know much

    • @Excelmacromastery
      @Excelmacromastery  Месяц назад +2

      I will cover this in a future video

    • @lonnieo4676
      @lonnieo4676 Месяц назад

      Libre office already uses python.. excel is playing catch up...

  • @vlastimilpetr9630
    @vlastimilpetr9630 Месяц назад +1

    Isn't Office Script the replacement for VBA?

  • @muhammadkausar2842
    @muhammadkausar2842 6 дней назад

    Sir please can u make a video on how to find the exact left and top position of mouse cursor. For example when we right click on any cell, then you may notice all the right click options are pop up with mouse cursor. I want this for to pop up the userform where my mouse cursor is.
    Please and also work for every type of screen size of laptop or desktop.
    I try some window API but didn't get perfect result. Thank you sir ❤

  • @anthonycroft7538
    @anthonycroft7538 Месяц назад

    I may be going against the general concensus here but this is entirely the wrong way to learn Python. If you have some existing VBA code and want a direct translation then maybe(?) Paul's video has some value, but if you want to learn Python and truly understand the possibilities in the language (+ its 000's of libraries), then learn the language properly and the varied ways you can accomplish tasks in a modern OO language. There are many many beginner texts out there but to suggest one, Eric Matthes (Crash Course in Python) - I have no affiliation - would be a pretty good starting point.
    If you want to use one of the several good Add-Ins for Python in Excel, then do the accompanying course for that Add-In to understand how the interaction with Excel works. Felix's course on his XLWings Add-In is very well put together. However the Add-Ins still assume some level of Python knowledge. Start with learning Python thoroughly from a good text or structured course.

    • @Excelmacromastery
      @Excelmacromastery  Месяц назад

      This video is aimed at VBA Developers who want to understand Python and how it works. It's not supposed to be a comprehensive course on Python.

  • @alecarmstrong7538
    @alecarmstrong7538 Месяц назад

    Hi - you should write a book on this!

  • @just_j9621
    @just_j9621 Месяц назад

    You're damn good

  • @dbdejonge2081
    @dbdejonge2081 Месяц назад

    .xlsm is often banned by companies. I had AutoCAD too, using VBA to control it and Excel too.

  • @cbbcbb6803
    @cbbcbb6803 Месяц назад

    What about LibreOffice Calc?

  • @ericxls93
    @ericxls93 Месяц назад

    After 20 years mastering VBA, then moving to Py. It has its place. Not good for the average guy and sharing is just not feasible. Why there is no python window (inside the excel gui) like VBA.

    • @Excelmacromastery
      @Excelmacromastery  Месяц назад

      Thanks for the feedback. Be interested to hear what you mean about "Not good for the average guy"

  • @lonnieo4676
    @lonnieo4676 Месяц назад +2

    who else things python is taking over,,, python simplified just did a stock forcasting app in python, no css, no javascript,,, amazing...

    • @nikolamilicevic5200
      @nikolamilicevic5200 Месяц назад

      Ive been hearing this from 2017.. And wasted time on learning stuff in python i didnt need for, ended up automating a bunch of worskheets in office and getting much credit for it

    • @Excelmacromastery
      @Excelmacromastery  Месяц назад

      It's been very popular for a long time and is definitely useful.

  • @marcq1588
    @marcq1588 Месяц назад +2

    The title of your video is highly misleading. You are not helping VBA developers at all. You are showing how Pyhthon can read data from an Excel source. Not the same.
    I was hoping to see VBA calling a Python script to speed up an otherwise lengthy VBA process and then return the control back to VBA.
    Not quite the same...

    • @Excelmacromastery
      @Excelmacromastery  Месяц назад +3

      ??? The title reflects exactly what's in the video. It does not mention anything about calling Python from VBA.

    • @mrashid229
      @mrashid229 Месяц назад +1

      @marcq1588 Possibly you watched a different video and commenting on that here, WRONG PLACE surely! The title is absolutely appropriate for this video. This will help VBA programmer shift faster to Python, knowing equivalent code and data structures with comparisons (similarities/dissimilarities). This also discusses differences in security and distributions of applications. Please watch the video again.

    • @daverichards2979
      @daverichards2979 Месяц назад

      I agree with the OP, until you can write and run python inside excel and run full functional code it won't replace VBA.

  • @A_Concerned_Citizen
    @A_Concerned_Citizen Месяц назад

    Who's a VBA developer lol

    • @hajajahirhussain6814
      @hajajahirhussain6814 Месяц назад +1

      I am😂

    • @byteseq
      @byteseq Месяц назад

      Idiot

    • @samhutchison8633
      @samhutchison8633 Месяц назад +3

      lol it’s actually still used a lot in industry on scada systems. It would be nice if Microsoft updated it

    • @TVYGANTAS
      @TVYGANTAS Месяц назад

      I am 😊