Skip to content

Commit 706c46a

Browse files
authored
Include VBA code to get Python exe path from registry
Added a section on retrieving Python executable path from Windows Registry using VBA.
1 parent 59d905a commit 706c46a

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

_posts/python/2025-02-04-run-python-from-excel.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,27 @@ Sub CalculateArea()
115115
objShell.Run PythonExePath & " " & PythonScriptPath, 0
116116
End Sub
117117
```
118+
### Getting python exe path from Windows Registry
119+
- In case you're planning to share this script with multiple people or running on different system
120+
- you'll have to use inbuilt python path from Windows registry
121+
- Use below code snippet to get python exe path from registry
122+
```vba
123+
Sub CalculateArea()
124+
125+
Dim scriptName As String
126+
scriptName = "Sample.py"
127+
128+
Dim objShell As Object
129+
Set objShell = CreateObject("WScript.Shell")
130+
131+
' Set working directory to workbook folder
132+
objShell.CurrentDirectory = ThisWorkbook.Path
133+
134+
' Run Python script (hidden window)
135+
objShell.Run "python.exe """ & scriptName & """", 0
136+
137+
End Sub
138+
```
118139

119140
### Conclusion
120141
- Now we can run our python script directly from excel file using excel VBA
@@ -123,4 +144,4 @@ End Sub
123144

124145

125146
> If you have any questions or want to discuss something : [Join our comment section](https://www.reddit.com/r/NodesAutomations/comments/1igllej/run_python_script_directly_from_excel_file_nodes/)
126-
{: .prompt-info }
147+
{: .prompt-info }

0 commit comments

Comments
 (0)