Export Python output to Excel cell

Hi,
I am trying to export a Python output to an Excel cell.
The Python code is:

import xlwings as xw
import time
import schedule
from yahoo_fin.stock_info import *
def show_name():
    print(get_live_price("4339.SR"))
schedule.every(3).seconds.do(show_name)
while 1:
    schedule.run_pending()
    time.sleep(1)
workbook = xlsxwriter.Workbook('sample_data4.xlsx')
sheet = workbook.add_worksheet()

sheet.write('A1', '')


workbook.close()

It worked with no problems as shown below:

In Excel I wrote the following in VBA:

Sub RunPythonScript()
Dim objShell As Object
Dim PythonExePath, PythonScriptPath As String
Set objShell = VBA.CreateObject("Wscript.Shell")
PythonExePath = """C:\Users\osalh\AppData\Local\Programs\Python\Python39\python.exe"""
PythonScriptPath = "C:\Users\osalh\Desktop\pythonProject\main.py"
objShell.Run PythonExePath & PythonScriptPath
Application.Goto Reference:="RunPythonScript"
End Sub

However, when I run the code it pops up a cmd with the output as follows:

, how to have the output be inside Excel ?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.