mhammond / pywin32

Python for Windows (pywin32) Extensions
4.92k stars 786 forks source link

Kwargs ignored #2077

Open maksim-pinguin opened 1 year ago

maksim-pinguin commented 1 year ago

I experienced that one (the last) keyword argument was ignored when used in excel com api.

The code below represents my experience and a workaround i discovered. First open a excel window than run the code. It will open a dialog box to input a cell selection. It will wait for input.

import win32com.client as com

Excel = com.Dispatch('Excel.Application')
kwargs = {'Prompt':'msg', 'Title':'title', 'Default':None, 'Left':None, 'Top':None, 'HelpFile':None, 'HelpContextID':None, 'Type':8}
Range = Excel.Application.InputBox(**kwargs)

Next select a range and click ok in the InputBox-Dialog. InputBox should return now. Range contains the top-left content of the selected range as a string. This is the default behavior if no Type argument is passed, which shouldn't bethecasesince we passed a non-default Type value. C.f. InputBox Doc

I originally posted this at xlwings/xlwings#1909 where someone else reported the same bug.

A workaround i discovered is to use positional args instead of kwargs i.e.:

Range = Excel.Application.InputBox('msg',None,None,None,None,None, None, 8) 

Edit: complete the example and rephrasing