In 2026, the most reliable way to call a Python script from Excel VBA and pass arguments is by using the Wscript.Shell object to execute a command-line string.1. The VBA CodeUse the Shell.Run method to execute the Python interpreter, followed by the script path and your arguments.vbaSub CallPythonWithArgs()
Dim objShell As Object
Dim pythonExe As String, scriptPath As String, args As String
Dim shellCommand As String

' Set paths (use triple quotes for paths with spaces)
pythonExe = """C:\Path\To\python.exe"""
scriptPath = """C:\Path\To\YourScript.py"""

' Define your arguments (space-separated)
args = """Arg1"" ""Arg2"""

' Build the full command string
shellCommand = pythonExe & " " & scriptPath & " " & args

' Initialize and run the shell
Set objShell = CreateObject("Wscript.Shell")
objShell.Run shellCommand, 1, True ' 1 = Show window, True = Wait for completion

MsgBox "Python execution finished!"
End Sub
Use code with caution.2. The Python Script (YourScript.py)To capture the arguments passed from VBA, use the built-in sys module.pythonimport sys

# sys.argv[0] is always the script name
# sys.argv[1], sys.argv[2], etc., are your passed arguments
if len(sys.argv) > 1:
first_arg = sys.argv[1]
second_arg = sys.argv[2]
print(f"Arguments received: {first_arg}, {second_arg}")

# Perform your operations here...
Use code with caution.Modern Alternatives for 2026Built-in Python in Excel: For many tasks, you can now bypass VBA entirely by using the official Excel Python integration with the =PY() function.xlwings: For more complex automation, the xlwings library remains a popular choice for bi-directional communication between Python and Excel.Wscript.Shell vs. VBA.Shell: Using Wscript.Shell is often preferred over the basic VBA.Shell function because it provides a WaitOnReturn parameter, ensuring your VBA macro pauses until the Python script is actually finished.