[python-win32] Excel advanced find
Dan Glassman
dan.glassman at charter.net
Wed Feb 15 21:47:37 CET 2006
Tim Golden wrote:
> [p.asselman at chello.nl]
>
> | Hello all,
> |
> | I'm having some trouble on the find function in Excel. A
> | simple Find statement works fine, but as soon as I want to
> | use an advanced option (xlByColumns) I get an error.
> |
>
> [... snip ...]
>
> | findcell =
> | xlApp.ActiveSheet.UsedRange.Find('FXN3',None,constants.xlValue
> | s,constants.xlWhole,constants.xlByColumns,constants.xlNext,Fal
> | se,False,None)
>
> | And this is the output:
> | C:\temp\python\excel>python findtest.py
> | $D$5
> | Traceback (most recent call last):
> | File "findtest.py", line 20, in ?
> | findcell =
> | xlApp.ActiveSheet.UsedRange.Find('FXN3',None,constants.xlValues,c
> | onstants.xlWhole,constants.xlByColumns,constants.xlNext,False,
> | False,None)
> | File "C:\Program
> | Files\python24\lib\site-packages\win32com\gen_py\00020813-000
> | 0-0000-C000-000000000046x0x1x4.py", line 21407, in Find
> | , MatchCase, MatchByte, SearchFormat)
> | pywintypes.com_error: (-2147352567, 'Exception occurred.',
> | (0, None, None, None,
> | 0, -2147352571), 9)
>
> *Very* quick and untested response: try using named
> params for the Find method. At the very least, you
> can then miss out the default values and it might
> narrow the prob. down
When you use None, the arguments will still be presented to the Excel
interface as Null. It would appear that the Excel interface doesn't
like either the [After] arg nor the [SearchFormat] arg to be Null.
Named arguments will work as suggested; this will prevent those
arguments from being presented to the Excel interface at all. You can
also use pythoncom.Missing, which is another way to prevent arguments
from being presented to the interface:
[code]
from pythoncom import Missing
usedRange = xlApp.ActiveSheet.UsedRange
usedRange.Find('FXN3', Missing, constants.xlValues,
constants.xlWhole, constants,xlByColumns,
constants.xlNext, False, False, Missing)
[/code]
--
-Dan Glassman
More information about the Python-win32
mailing list