+ Reply to Thread
Results 1 to 4 of 4

VBA running python code

Hybrid View

  1. #1
    Registered User
    Join Date
    06-10-2021
    Location
    Brisbane, Australia
    MS-Off Ver
    2016
    Posts
    19

    VBA running python code

    I am trying to have a vba which will run a python code. Nothing seems to work.

    This is what I have so far

    Sub RunPythonScript()
    'Procedure to run a Python Script in a VBA Procedure
     
        'Declaration
        Dim objShell As Object 'For the Shell
        Dim Pythonexe, PythonScript As String
         
        'Create the Shell Object
        Set objShell = VBA.CreateObject("Wscript.Shell")
         
        Pythonexe = """C:\Users\61458\Desktop\TEST\Windows32.exe\crawl.exe """ 'path of the crawl.exe
       
         
        'Run your Python script
        objShell.Run Pythonexe 'two arguments
     
        'Free variables for memory
         Set objShell = Nothing
         
    End Sub
    hopefully someone can help

    Thank you in advance
    Last edited by 6StringJazzer; 06-13-2021 at 08:44 AM. Reason: cleaned up code tags

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner VA USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,664

    Re: VBA running python code

    First I would get rid of the inner quotes on the path. They are not needed when you are using a String variable for the argument

    Pythonexe = "C:\Users\61458\Desktop\TEST\Windows32.exe\crawl.exe" 'path of the crawl.exe
    Also you declare but never use variable PythonScript.

    Alternative method:

    Sub RunPythonScript()
    'Procedure to run a Python Script in a VBA Procedure
         
        'Run your Python script
        Shell("C:\Users\61458\Desktop\TEST\Windows32.exe\crawl.exe", 1)
         
    End Sub
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    06-10-2021
    Location
    Brisbane, Australia
    MS-Off Ver
    2016
    Posts
    19

    Re: VBA running python code

    sorry for late reply. It did not work. Nothing happened

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner VA USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,664

    Re: VBA running python code

    What happens if you enter that same path into a cmd window?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Running a Python Script from Excel VBA
    By DeanMcK in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-28-2021, 05:26 PM
  2. Python Package Openpyxl Code Help, Working with Columns
    By ricmacharia in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 0
    Last Post: 06-10-2019, 02:10 AM
  3. Calling Python code from Excel VBA
    By trizzo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-17-2017, 04:21 AM
  4. code works running in visual basic editor but not when running from Excel macro
    By smporco in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-06-2016, 05:44 PM
  5. [SOLVED] Porting Python code to VB?
    By Rhudi in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-26-2016, 01:17 PM
  6. [SOLVED] How to prevent worksheet code from running while Module Macro is running:
    By Chad Bateman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-11-2015, 09:26 AM
  7. Can you use (or compile?) Python code in Excel
    By mrvp in forum The Water Cooler
    Replies: 7
    Last Post: 06-08-2014, 06:49 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1