Evgeniy Rasyuk
Evgeniy Rasyuk

Reputation: 327

pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147352565), None)

I was created example from http://docs.xlwings.org/en/stable/vba.html /Python 3.5.1 |Anaconda 2.5.0 (32-bit)| (default, Jan 29 2016, 15:46:01)/ and got error

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

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

  File "C:\Python3\mymodule.py", line 7, in rand_numbers

    n = int(Range('Sheet1', 'B1').value)  # Write desired dimensions into Cell B1

  File "C:\Python3\lib\site-packages\xlwings\main.py", line 701, in __init__

    self.xl_sheet = xlplatform.get_worksheet(self.xl_workbook, sheet_name_or_index)

  File "C:\Python3\lib\site-packages\xlwings\_xlwindows.py", line 240, in get_worksheet

    return xl_workbook.Sheets(sheet)

  File "C:\Python3\lib\site-packages\win32com\client\dynamic.py", line 192, in __call__

    return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None)

pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147352565), None)



Press Ctrl+C to copy this message to the clipboard.
---------------------------
OK   
---------------------------

Upvotes: 15

Views: 66716

Answers (4)

Simon
Simon

Reputation: 21

in my case I was trying to refresh an Excel file but one of the required add-ins was disabled.

Upvotes: 1

Rahib
Rahib

Reputation: 512

If the above solutions did not work then my best guess is that the excel file you using is not in focus, I had the same issue while working with xlwing. All you need to do is once select the Excel (kind of set focus event of excel) file and then run the python code.

Upvotes: 0

trislong
trislong

Reputation: 81

I've found that you can't use relative paths, and this is the error you get if you do use a relative path.

pass the relative path with os.path.abspath(rel_path) to open the file.

Upvotes: 8

Felix Zumstein
Felix Zumstein

Reputation: 7070

Hey so the error means:

>>> import win32api
>>> win32api.FormatMessage(-2147352565)
'Invalid index.\r\n'

So my guess is that you're trying to write to an inexistent sheet (and yes, we shall be working on easier-to-understand error messages...)

Upvotes: 30

Related Questions