1

This simple code is not working. I'm sure that the filepath is correct, but it seems that the problem is coming from a failure to open/add the workbook with the "Workbooks.Add" function. Here's the code:

from win32com.client import Dispatch

#processing the results
excel = Dispatch('Excel.Application')
excel.Workbooks.Add('C:\\Documents and Settings\\dell600\\My Documents\\Webscraping Output\\Results\\Processed Results.xls')
excel.Run('Apply_Process')
excel.DisplayAlerts = 0
excel.Quit()
excel.DisplayAlerts = 0

Here's the error message:

Traceback (most recent call last):
File "TestMacro", line 6, in <module>
excel.Run('Apply_Process')
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line282, in _ApplyTypes_
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occured.', (0, None, None, None, 0, -2146771191), None)
Samsun Knight
  • 51
  • 1
  • 3

1 Answers1

0

Make sure you have the following: 1) The right path, double check it, you also have to have the right extension 2) Make sure the file is open, I used excel.workbooks.Open(path) 3) You need to have macros enabled in excel, if your running 2007 or later, you'll have to run a .xlsm

Voltage Spike
  • 162
  • 4
  • 15