使用 XLwings 将几个变量从 Excel 传递到 Python

Passing several variables from Excel to Python with XLwings

我有与此相同的问题 post 但是有多个变量(并且用宏而不是函数)()

我试试这个

Sub Hello ()
    Dim name,name2 As String
    RunPython ("import Test; Test.sayhi('" & Name1 & " , " & Name2 & "')")
End sub

但是我得到这个错误:

---------------------------
Error
---------------------------
Traceback (most recent call last):

  File "<string>", line 1, in <module>

TypeError: sayhi() missing  required positional arguments: 'Name2' 

请问如何克服这个错误?

感谢您的帮助

您的字符串解析为单个参数。像这样修复单引号:

RunPython ("import Test; Test.sayhi('" & Name1 & "' , '" & Name2 & "')"