Combine Excel & Python | Execute a Python Script from Excel using xlwings | Works on Windows & macOS

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ต.ค. 2024

ความคิดเห็น • 63

  • @CodingIsFun
    @CodingIsFun  3 ปีที่แล้ว +3

    *I will be here in the comments section. For any issues, please provide your exact error message, and I will try to help.*

    • @CodingIsFun
      @CodingIsFun  2 ปีที่แล้ว

      @@SBHATY0U When do you get the error? When selecting the .bas file and importing it? What is the entire error message? Have you tried to run a quickstart project as shown in the video?

    • @CodingIsFun
      @CodingIsFun  2 ปีที่แล้ว

      @@SBHATY0U Ok, but why would you like to replace the .bas file if it is working? As mentioned in the video, when creating a new project, you could include the xlwings .bas file to execute a Python file from Excel when mentioned in the video.

  • @sigge5395
    @sigge5395 ปีที่แล้ว +1

    Absolutely loved this, answered most of my questions. Thanks!!

    • @CodingIsFun
      @CodingIsFun  ปีที่แล้ว

      Happy to hear that it was useful; thank you for taking the time to leave a comment and for watching the video! :)

  • @IgnacioAguilarToledo
    @IgnacioAguilarToledo 7 หลายเดือนก่อน

    Very good explanation! Thanks

    • @CodingIsFun
      @CodingIsFun  6 หลายเดือนก่อน

      Thanks for the positive feedback! Appreciate you taking the time to leave a comment. Cheers, Sven ✌️

  • @ojschoolz
    @ojschoolz 2 ปีที่แล้ว +1

    Hello, I'm trying to follow along with your video but i am getting the error "'xlwings' is not recognized as an internal or external command,
    operable program or batch file." when trying to quickstart

    • @CodingIsFun
      @CodingIsFun  2 ปีที่แล้ว

      Hi Ojschoolz. Have you installed xlwings by running 'pip install xlwings --upgrade'?

  • @automateboringstuffwithraj
    @automateboringstuffwithraj 2 หลายเดือนก่อน

    Can we use custom python UDFs in all excel files like xlsx, and unsaved excel files as well?

  • @praveenurugonda8023
    @praveenurugonda8023 3 ปีที่แล้ว

    Hi sir. Your videos are amazing sir

    • @CodingIsFun
      @CodingIsFun  3 ปีที่แล้ว

      Thank you Praveen Urugonda, I'm happy to hear that you've been finding the videos useful. Thanks for taking the time to leave a comment and for watching!

  • @mando2391
    @mando2391 3 ปีที่แล้ว +1

    Great video, any suggestions on how to make it so another user doesn't need python to run it on excel?

    • @CodingIsFun
      @CodingIsFun  3 ปีที่แล้ว +1

      Thanks for watching. You could transform your Python script into a standalone executable file.
      Here is one example from 'Python simplified':
      th-cam.com/video/Y0HN9tdLuJo/w-d-xo.html
      I hope this helps!

  • @GeoteknikIndonesia
    @GeoteknikIndonesia ปีที่แล้ว

    Amazing man. Can I ask u a question. So you show at minutes 9:05 on how to run the script from a folder "script". you define the python path as %%userprofile\dektop\scripts . But if you have to move the whole directory somewhere else, the scripts will not be working right? since the python path is fixed. Is there any way to define the python script relative to the "script" folder but without rechange/readjust the pyhton path again once we move the directory ?

    • @CodingIsFun
      @CodingIsFun  ปีที่แล้ว

      Thanks for watching. You could use the Standalone option, as shown at 3:40 min and then keep the path flexible using VBA. Happy Coding!

  • @saurabhchougule9483
    @saurabhchougule9483 6 หลายเดือนก่อน

    Could you please help.
    Df = sheet.range('A1').expand().options(pd.Dataframe, index=False).value
    This is not taking in the entire data from excel if the first column has blank values. Any workaround to get whole data ?

    • @CodingIsFun
      @CodingIsFun  6 หลายเดือนก่อน +1

      Thanks for watching. You could try to use the "used_range" property on the Sheet object: docs.xlwings.org/en/stable/api/sheet.html#xlwings.Sheet.used_range
      Happy Coding! Cheers, Sven ✌️

    • @saurabhchougule9483
      @saurabhchougule9483 6 หลายเดือนก่อน

      @@CodingIsFunThanks for replying. So used_range also did not work for me. I used current_region and it worked just right!

  • @calichito94
    @calichito94 ปีที่แล้ว

    I just have a question: I have a table in a excel sheet, How i could insert a new row to put data in that new row inserted? Thanks a lot

    • @CodingIsFun
      @CodingIsFun  ปีที่แล้ว

      Thanks so much for watching the video and leaving a comment! Your request is definitely noted. However, I get a ton of requests for custom solutions and, as much as I'd love to help everyone out, I just don't have the time in my schedule to develop and test all of them. I hope you can understand. Happy Coding!

  • @JITISH1
    @JITISH1 2 ปีที่แล้ว

    Hi, thank you for the great tutorial. When I click the Run Main button, why does xlwings close my excel file and delete it from the folder as well?

    • @CodingIsFun
      @CodingIsFun  2 ปีที่แล้ว

      Thanks for watching and for your question. Hard to tell from a distance why you are facing an error. Sorry that I cannot help.

  • @theDavidJVarela
    @theDavidJVarela ปีที่แล้ว

    I am getting the following error while using macOS and OneDrive: Error Traceback (most recent call last): File "", line 1, in TypeError: 'module' object is not callable. I tried the troubleshooting section of the xlwings page, but it is not obvious to me how to execute some of the troubleshooting sections of the page. I haven't figured out how to Add the directory of your Python source file to the PYTHONPATH-again, either via Ribbon or xlwings.conf sheet. Can someone please help me understand how to address this?

    • @theDavidJVarela
      @theDavidJVarela ปีที่แล้ว

      The error seems to be associated with the "-" in "OneDrive-Personal"

  • @me_3890
    @me_3890 2 ปีที่แล้ว

    Hi,
    thanks for your helpful videos!
    The part starting at 12:07 seems to be the one relevant for me at the moment but I’m working with Jupyter Notebooks. I followed your instructions but Excel “Could not find interpreter!“ - can you help?

    • @CodingIsFun
      @CodingIsFun  2 ปีที่แล้ว

      You might want to check if you have specified a Python interpreter path in your xlwings config file. Have a look at 7:24 min.

  • @elinversordepastos3204
    @elinversordepastos3204 2 ปีที่แล้ว +1

    This content is just EXCELLENT. Thank you very much!

    • @CodingIsFun
      @CodingIsFun  2 ปีที่แล้ว

      Glad you enjoyed the content. Thanks for watching the video and taking the time to leave a comment! :)

  • @praveenurugonda8023
    @praveenurugonda8023 3 ปีที่แล้ว

    I have doubt . I created python file in anaconda environment. I can not able to run that code by giving in macro paths only. Can you guide how to run anaconda created python file in macro by giving their paths

    • @CodingIsFun
      @CodingIsFun  3 ปีที่แล้ว

      Do you get any error messages? Is it working when you leave the python script in the same directory as the workbook?

    • @praveenurugonda8023
      @praveenurugonda8023 3 ปีที่แล้ว

      Thank you for your reply

  •  ปีที่แล้ว

    THANKSSSSSSSSSSSSSSS!!!!

    • @CodingIsFun
      @CodingIsFun  ปีที่แล้ว

      My pleasure! Appreciate you taking the time to watch and leave a comment. 👍

  • @DewanshiRamani
    @DewanshiRamani 4 หลายเดือนก่อน

    Hello, how to use xlwings server in wsl system step by step instraction

    • @CodingIsFun
      @CodingIsFun  4 หลายเดือนก่อน

      Thank you very much for watching the video and your comment. Your requirements are well noted. Yet, I receive many requests for creating individual solutions. As much as I want to help, I simply do not find the time in my daily schedule to develop & test all the different requests. I hope you can understand. Thank you! Cheers, Sven ✌️

  • @nicholasciacca1201
    @nicholasciacca1201 ปีที่แล้ว

    hello @codingisfun, when I try to make my code an EXE file using psgcompiler it gives me an error: 'Failed to execute script 'pyi_rth_win32comgenpy' due to unhandled exception: Module 'pythoncom' isn't in frozen sys.path'
    please help :)

    • @CodingIsFun
      @CodingIsFun  ปีที่แล้ว

      Thanks for watching. Hard to tell from a distance. Sorry that I cannot help

  • @confidential303
    @confidential303 2 ปีที่แล้ว

    Hi, instead of stackoverflow I am heading towards here :P , I got a question, I made in excel a bot with chromedriver which was getting me crypto/stock prices so to calculate my value of my portfolio. But since last it didnt work anymore saying chrome version 95 is not supported by this chromedriver. So I tried to install the latest version..I just replaced the old with the new one..it didn't worked but somehow in the evening all of sudden it did work, but now the fun part..Malwarebytes wanted to do a routine scan ..I said yes and It found malware.heurestic ..so it was a zero day something..so I am not sure now, is it safe to use the latest version of chromedriver, are there any issues with it? I do want a clean system, dont like to get compromised.

    • @CodingIsFun
      @CodingIsFun  2 ปีที่แล้ว

      Great question! ChromeDriver is actually open-source. I would consider it as safe to use 👍

  • @heheh92
    @heheh92 2 ปีที่แล้ว

    after doing the quickstart I get a message bash is a directory. please help!

    • @CodingIsFun
      @CodingIsFun  2 ปีที่แล้ว

      Is that the full error message? Can you cd to your desktop and try to run the quickstart command again?

  • @mypage9331
    @mypage9331 2 ปีที่แล้ว

    Hello! Will xlwings work with the Microsoft365 version of Excel?

  • @slickbuyers
    @slickbuyers 2 ปีที่แล้ว

    "xlwings' is not recognized as an internal or external command," my issue with the addin install

    • @CodingIsFun
      @CodingIsFun  2 ปีที่แล้ว

      Did you install the library?? pip install xlwings

    • @slickbuyers
      @slickbuyers 2 ปีที่แล้ว

      Thank you for your response, ya it installed correctly,but the add-in is showing problem's

    • @CodingIsFun
      @CodingIsFun  2 ปีที่แล้ว

      @@slickbuyers Ok, then you might want to check out the following site: docs.xlwings.org/en/stable/troubleshooting.html

    • @slickbuyers
      @slickbuyers 2 ปีที่แล้ว +1

      @@CodingIsFun ok thank you.

  • @lockmaboc9416
    @lockmaboc9416 2 ปีที่แล้ว

    Hi ! Thanks a lot for your video ! It's great ! Maybe you can help me, I followed the same things you have done. First, i don't have any "xlwings" my ribbon, so I added one using : xlwings quickstart demo --addin --ribbon
    After that, every time i tried tu run the macro i got an error : Sub not define
    And I tried everything i knew it didn't works.
    Please can you help me ? In fact i already have a python script that I coded on my Windows Pc and I linked it to an excel file in order to run the code every time I push the button.
    I want to do the same on my Macbook and it driving me craizy cause it doesn't works
    Please !

    • @CodingIsFun
      @CodingIsFun  2 ปีที่แล้ว +1

      Thanks for watching. How about starting with a quickstart project by running "xlwings quickstart myproject" first, and then use the generated Python file to adjust it to your needs. Happy Coding!

    • @lockmaboc9416
      @lockmaboc9416 2 ปีที่แล้ว

      @@CodingIsFun thanks a lot for your message !
      That's what i have done at least 10 times, but each time the VBA macro got a error : Sub is not define.
      I don't understand why cause i wrote the same code than you .... it's so annoying 😭

    • @CodingIsFun
      @CodingIsFun  2 ปีที่แล้ว +1

      @@lockmaboc9416 I only have two possible fixes:
      1) Ensure to activate xlwings. Open the VBA Editor, navigate to Tools -> References and tick the box for xlwings
      2) Upgrade xlwings by running 'prip install xlwings --upgrade'

    • @lockmaboc9416
      @lockmaboc9416 2 ปีที่แล้ว

      @@CodingIsFun I'm gonna try today thnajs a lot for your reply it help me a lot !! I have to do it for an important internship🤞🤞 hopefully it gonna works

  • @bosco9236
    @bosco9236 ปีที่แล้ว

    I suppose this only woks on Excel 365.

    • @CodingIsFun
      @CodingIsFun  ปีที่แล้ว

      Thanks for watching. No, it also works with other Excel versions

    • @bosco9236
      @bosco9236 ปีที่แล้ว

      @@CodingIsFun Good to know, I'll give it a shot. Thanks.

  • @sureshgoku
    @sureshgoku 3 ปีที่แล้ว

    Can there be a list validation using python

    • @CodingIsFun
      @CodingIsFun  3 ปีที่แล้ว

      Thanks for watching the video. Yes, that is possible. See example below:
      import xlwings as xw #pip install xlwings
      wb = xw.Book('Book1.xlsx')
      sht = wb.sheets['Sheet1']
      rng = sht.range('A1')
      validation_list = "Ahoy, From, Coding, Is, Fun"
      dv_type = xw.constants.DVType.xlValidateList
      dv_alertstyle = xw.constants.DVAlertStyle.xlValidAlertStop
      dv_operator = xw.constants.FormatConditionOperator.xlEqual
      rng.api.Validation.Add(dv_type, dv_alertstyle, dv_operator, validation_list)

  • @rajesh9sn
    @rajesh9sn 2 ปีที่แล้ว

    Hi I am using vba to run a python script. However, the python script runs twice.
    Option Explicit
    Private Sub Worksheet_Calculate()
    Dim Ret_Val
    If Range("A1|).Value > 0 then
    Ret_Val = Shell("C:\Program Files\Python37\python.exe " & "F:\fut.py")
    End If
    End Sub
    In Cell A1 I have this formula COUNTIFS($J$28:$K$32,">"&$B$4)+COUNTIFS($J$18:$K$22,">"&$B$4)+COUNTIFS($J$38:$K$42,">"&$B$4)
    my python code
    import pyttsx3
    engine = pyttsx3.init()
    engine.say(Hello How are you"')
    engine.runAndWait()
    what wrong am i doing?
    Thank you.

    • @CodingIsFun
      @CodingIsFun  2 ปีที่แล้ว +1

      I am not sure why your code got executed twice. You might want to use the built in VBE debug tools to step into your code:
      www.screencast.com/t/KS9Xh4Lz
      Debug Video: th-cam.com/video/GGfvTFA7ZlI/w-d-xo.html