在 xlwings RunPython VBA 函数中传递参数
passing argument in xlwings RunPython VBA function
我正在使用 python 从 excel 个工作表中获取一些数据。我正在使用 xlwings 来完成这个。我试图将当前工作簿的路径传递到我的文件,它可以在其中使用它来查找 Excel 书。我不能使用 xlwings UDF。
这是我的 VBA 代码:
Sub Button1_Click()
RunPython ("import exceltest; exceltest.excelTest('" & ThisWorkbook.FullName & "')")
End Sub
这是我的 exceltest.py Python 代码:
def excelTest(path_of_file):
print (path_of_file)
这是我遇到的错误:
错误
File "<string>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
如有任何帮助,我们将不胜感激!
使用工作簿的完整路径(实际路径而不是 ThisWorkbook.FullName
并像这样构造它 r'''myfullpath\mysubfolder\myExcelfile'''
我需要使用 RunPython ("import exceltest; exceltest.excelTest(r'" & ThisWorkbook.FullName & "')")
我正在使用 python 从 excel 个工作表中获取一些数据。我正在使用 xlwings 来完成这个。我试图将当前工作簿的路径传递到我的文件,它可以在其中使用它来查找 Excel 书。我不能使用 xlwings UDF。
这是我的 VBA 代码:
Sub Button1_Click()
RunPython ("import exceltest; exceltest.excelTest('" & ThisWorkbook.FullName & "')")
End Sub
这是我的 exceltest.py Python 代码:
def excelTest(path_of_file):
print (path_of_file)
这是我遇到的错误:
错误
File "<string>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
如有任何帮助,我们将不胜感激!
使用工作簿的完整路径(实际路径而不是 ThisWorkbook.FullName
并像这样构造它 r'''myfullpath\mysubfolder\myExcelfile'''
我需要使用 RunPython ("import exceltest; exceltest.excelTest(r'" & ThisWorkbook.FullName & "')")