Is there a way to make Python run with Excel autom

2019-08-18 07:48发布

I am trying to automate an Excel sheet by creating a button. I want that when this button is pressed my Python script should start running and its output should be written back into the Excel sheet.

To make the Python script work, I integrated it with VBA. When the button is clicked, the following code runs:

Sub Macro2()
    RetVal = Shell('path to python file', vbNormalFocus)
End Sub

My Python script is very simple:

import openpyxl
wb = openpyxl.load_workbook('Prior Example.xlsm')
sheet = wb.get_sheet_by_name('UI')
sheet['F10'] = 'hello'

However, when I press the button, I do not get any output in F10. Is there something wrong with the code/is there a simpler way to do this?

标签: python excel vba
0条回答
登录 后发表回答