I am getting some data from excel sheets using python. I'm using xlwings to accomplish this. I am trying to pass the path to the current workbook to my file, where it can use it to find the Excel book. I cannot use xlwings UDF's.
Here's my VBA code:
Sub Button1_Click()
RunPython ("import exceltest; exceltest.excelTest('" & ThisWorkbook.FullName & "')")
End Sub
Here's my exceltest.py Python code:
def excelTest(path_of_file):
print (path_of_file)
Here's the error I'm getting:
Error
File "<string>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Any help would be greatly appreciated!
ThisWorkbook.FullNameprobably has a special slash character in it that Python is interpreting as something else. What characters follow the slashes in the path?Debug.Print ThisWorkbook.FullNameit outputsC:\Users\gageb\Desktop\test.xlsm\U...Can you hard code the workbook path, or will it vary? If you can, try the answer I suggested.r'''C:\Users\gageb\Desktop\test.xlsm'''