Menu

Run-time error '440':

atrulz2
2014-02-07
2014-02-07
  • atrulz2

    atrulz2 - 2014-02-07

    Hi, there, first of all, I must say a great tool.

    However, I quickly ran into few problems.

    Hi Eric,

    Great ExcelPython solution I must say.

    However, I ran into a few problems while working with your module and I hope you could help me with it.

    I am trying to return a xml data (customer details) which I parsed in python. I understand some of the characters in the my dataset, could be non ascii and that may be causing this. However, the code works just fine in python, but returns the following error when I try to pull it through VBA.

    Run-time error '440':

    'ascii' codec can't encode character u'\xe9'in position 64: ordinal not in range(128)

    My VBA code uses your simple example to pull data.

    Set res = PyCall( _
    PyModule("MyScript", AddPath:=PyPath), "function")

    ActiveSheet.Range("A1").Value = PyVar(res)
    

    Secondly, I am trying to populate excel with my parsed xml data. My Python code runs a loop with each iteration providing one customer detail. I haven't figured how can I populate excel rows with each python iteration through your module, as a function returns the last row. Do I have the load entire data into a list or something in python and pull it in VBA and then re-parse it, or is it possible to read data dynamically from python and populate excel meanwhile.

    I hope I made sense. Hoping to hear from you.

     

    Last edit: atrulz2 2014-02-07
  • Eric Reynolds

    Eric Reynolds - 2014-02-07

    Hi,

    1) I tried the following in the VBA immediate window

    ?PyVar(PyEval("u'abc\xe9def'"))
    abcédef
    

    so the problem doesn't seem to be related to with how ExcelPython converts Python unicode objects with non-ASCII characters into VBA strings. The error you describe seems to be an Python exception which get raised when you convert non-ASCII strings into str objects:

    >>> str(u'abc\xe9def')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    UnicodeEncodeError: 'ascii' codec can't encode
    character u'\xe9' in position 3: ordinal not in range(128)
    

    So I'd need you to give me a bit more details of what your function does and at which line in the Python code the error is generated (the VBA error should tell you this, as it gives you a print out of the exception).

    2) At the moment it's not possible to populate the Excel spreadsheet from the Python code. I did start working on something which enabled you to do this, but right now it's not complete or functional. My suggestion is to populate a list while your function runs, then return the list to Excel.

    Best regards,

    Eric.

     

Log in to post a comment.