Pywintypes Com Error Excel
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers pywintypes.com_error exception occurred or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x com_error: (-2147352567, 'exception occurred.', (0, none, none, none, 0, -2147352565), none) Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it pywintypes.com_error invalid class string only takes a minute: Sign up 'Run Excel File From Python' Error up vote 0 down vote favorite When I try to open an excel file by calling EXCEL itself from python, I get error. How can I fix that?
Pywintypes.com_error Python
Thanks in advance. The code is: from win32com.client import Dispatch xl = Dispatch('Excel.Application') wb = xl.Workbooks.Open(r"data\Modules.xls") And the error is: pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft Office Excel', u"'data\Modules.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct.\n\nIf you are trying to open the file from your list of most recently used files, make sure that the file has not been renamed, moved, or deleted.", u'C:\Program Files (x86)\Microsoft Office\Office12\1033\XLMAIN11.CHM', 0, -2146827284), pywintypes.com_error class not registered None) python winapi excel share|improve this question edited May 5 '11 at 5:16 asked May 4 '11 at 7:08 Shansal 3451821 2 Is the python code file in the directory where the data directory exists? Try giving full path of the xls file instead of relative path. –shahkalpesh May 4 '11 at 7:12 It is in the same directory. It must be this way. I shouldnt give the full path. –Shansal May 4 '11 at 14:04 I know that's not what you are asking for but you should try the xlrd module instead of using win32com. Will make your life easier. –ktdrv May 4 '11 at 17:39 Can I open an excel file in EXCEL itself by using xlrd? –Shansal May 5 '11 at 5:14 add a comment| 3 Answers 3 active oldest votes up vote 5 down vote accepted Use os.path.abspath() to convert file system paths to absolute. The current working directory of yout Python and Excel process is not the same. http://docs.python.org/library/os.path.html share|improve this answer answered May 4 '11 at 11:25 Mikko Ohtamaa 36.1k18120236 What path should I supply to that function? –Shansal May 4 '11 at 14:02 When I use "wb = xl.Workbooks.Open(os.path.abspath(r"data\Modules.xls"))", I dont get error. But I cant see any Excel file opened. Even if I see an excel instance in task manager. –Shansal May 4 '11 at 14:14 os.path.join(os.getcwd(), "p
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of python catch com_error this site About Us Learn more about Stack Overflow the company Business
Win32api Python
Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask
Pywin32
Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign http://stackoverflow.com/questions/5879754/run-excel-file-from-python-error up Is there a way to decode numerical COM error-codes in pywin32 up vote 24 down vote favorite 6 Here is part of a stack-trace from a recent run of an unreliable application written in Python which controls another application written in Excel: pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2146788248), None) Obviously something has gone wrong ... but what?[1] These http://stackoverflow.com/questions/521759/is-there-a-way-to-decode-numerical-com-error-codes-in-pywin32 COM error codes seem to be excessively cryptic. How can I decode this error message? Is there a table somewhere that allows me to convert this numerical error code into something more meaningful? [1] I actually know what went wrong in this case, it was attempting to access a Name prperty on a Range object which did not have a Name property... not all bugs are this easy to find! python windows excel com pywin32 share|improve this question asked Feb 6 '09 at 19:18 Salim Fadhley 5,916125285 add a comment| 5 Answers 5 active oldest votes up vote 33 down vote accepted You are not doing anything wrong. The first item in your stack trace (the number) is the error code returned by the COM object. The second item is the description associated with the error code which in this case is "Exception Occurred". pywintypes.com_error already called the equivalent of win32api.FormatMessage(errCode) for you. We'll look at the second number in a minute. By the way, you can use the "Error Lookup" utility that comes in Visual Studio (C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\ErrLook.exe) as a quick launch
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more http://stackoverflow.com/questions/3718037/error-while-working-with-excel-using-python about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each https://mail.python.org/pipermail/python-win32/2011-May/011494.html other. Join them; it only takes a minute: Sign up Error while working with excel using python up vote 4 down vote favorite 1 while my script is updating one excel same time if i am going to do exception occurred any other work manually with another excel error occurs i am using dispatch from win32com.client import Dispatch excel = Dispatch('Excel.Application') excel.Visible = True file_name="file_name.xls" workbook = excel.Workbooks.Open(file_name) workBook = excel.ActiveWorkbook sheet=workbook.Sheets(sheetno) I am geting error like this (, com_error(-2147418111, 'Call was rejected by callee.', None, None) Is there is any way to overcome it ..can i update another excel without geting error.. python excel share|improve this question asked Sep 15 '10 at 13:26 sagar 3381825 pywintypes com error Include the entire traceback so we can see what line caused the error. A few comments: Firstly, you have two variables workbook and workBook that differ only by one capital letter. Probably not a good idea. Secondly, there is no reason to grab the ActiveWorkbook as you already have a reference to it on the previous line (an opened workbook is immediately active). Thirdly, you do not specify a path for your filename, so if your python code and excel worksheet are in different directories, Open will fail. Finally, perhaps sheetno is out of range. Excel holds sheets in a 1-based array. –Steven Rumbalski Sep 15 '10 at 15:41 add a comment| 2 Answers 2 active oldest votes up vote 4 down vote This error occurs because the COM object you're calling will reject an external call if it's already handling another operation. There is no asynchronous handling of calls and the behavior can seem random. Depending on the operation you'll see either pythoncom.com_error or pywintypes.com_error. A simple (if inelegant) way to work around this is to wrap your calls into the COM object with try-except and, if you get one of these access errors, retry your call. For some background see the "Error Handling" section of the chapter 12 excerpt from Python Programming on Win32 by Mark Hammond & Andy Robinson (O'Reilly 2000). There's also some useful info specifically abo
[python-win32] outlook new mail handling Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] Sadly this is all under the control of Excel, so I've no good advice. The poor advice I can offer is (1) for your own piece of mind, see if you can get the same basic behaviour with wscript and a .vbs script, (2) to try and see if you can find a similar problem in any language/environment (eg, wscript) and how they worked around it and finally (3) see if you can worm around it by catching that exception then discarding the object you have and re-connecting to that instance using normal Dispatch(). HTH, Mark On 25/05/2011 5:08 AM, Mark Mordeca wrote: > Greetings, > > I am having a problem with using win32com to open an instance of Excel > when there is already one open. I would appreciate any help. > > My example goes as follows: > > The user has an Excel file (and therefore an EXCEL.exe process) open > already. > > I do: > > xl=win32com.client.DispatchEx("Excel.Application") #create a new > instance of EXCEL.exe that will not interfere with the already open > process. It remains hidden. > > book=xl.Workbooks.Open(filename) #open the excel file > > There are now 2 EXCEL.exe's in the Task Manager. > > After this, but before I am done with the Excel file I opened with > DispatchEx, the user then closes their open Excel file. There is now > only one EXCEL.exe in the task manager, supposedly the one that I opened > with DispatchEx. > > I then call: > > try: > > book.Close() > > and receive the error: > > Exception pywintypes.com_error: com_error(-2147418111, 'Call was > rejected by callee.', None, None) > > I then go into an except statement and do: > > nbooks=xl.Workbooks.Count <--FAILS HERE > > if not xl.Visible and nbooks==0: > > # if excel is not visible and there are no books open, > close excel. > > # Do this because another program may have excel open > in the background. > > print "Asking Excel to Quit" > > xl.Quit() > > xl=None > > At "FAILS HERE" I get the same error again: "Exception > pywintypes.com_error: com_error(-2147418111, 'Call was rejected by > callee.', None, None)" and the EXCEL.exe is left hanging in the process > manager, which I have to now manually kill. > > Can anyone help me with this error and how to keep connected to the > Excel instance I opened with DispatchEx no matter what the user does > with their own open Excel which includes the user closing it? > > Thank you