Jun-25-2022, 10:02 AM
Hi,
I am trying to get Python outputs to be in Excel.
The code is:
However, the Excel file sample_data4.xlsx is unreachable as shown below:
[attachment=1811]
Although, the Excel file is located in the same folder as shown below:
[attachment=1812]
Then in Excel VBA I entered :
After running the above code the output is given in the cmd file as follows:
[attachment=1806]
How to have the output in an Excel cell?
I am trying to get Python outputs to be in Excel.
The 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()[attachment=1805]
However, the Excel file sample_data4.xlsx is unreachable as shown below:
[attachment=1811]
Although, the Excel file is located in the same folder as shown below:
[attachment=1812]
Then in Excel VBA I entered :
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[attachment=1807]
After running the above code the output is given in the cmd file as follows:
[attachment=1806]
How to have the output in an Excel cell?