FishMonkey
FishMonkey

Reputation: 198

passing argument in xlwings RunPython VBA function

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!

Upvotes: 0

Views: 1382

Answers (2)

FishMonkey
FishMonkey

Reputation: 198

I needed to use RunPython ("import exceltest; exceltest.excelTest(r'" & ThisWorkbook.FullName & "')")

Upvotes: 0

MBB70
MBB70

Reputation: 367

Use the full path of your workbook (the actual path instead of ThisWorkbook.FullName and structure it like this r'''myfullpath\mysubfolder\myExcelfile'''

Upvotes: 1

Related Questions