[python-win32] Calling Excel function GetSaveAsFilename, parameter ignored

Jason Veldicott jasonveldicott at gmail.com
Wed Jul 13 08:36:24 CEST 2011


Hi,

I am wanting to display a file "Save As..." dialog in Excel through Pywin.
 I am doing this by calling
Application.GetSaveAsFilename<http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel._application.getsaveasfilename.aspx>().
 The problem however is that the parameter supplied to this function,
InitialFilename, seems to be ignored by Excel.  Perhaps it's not getting
through to Excel.  When VBA was used to call the same function, the initial
filename displayed correctly.

Not being able to specify an initial filename is inconvenient if not
unsatisfactory from application usability point of view, and one wonders if
other functions might also be affected.   If anyone has any suggestions as
to why this might be happening, or even what a solution may be, I would be
glad to hear from you.

I am using Python 2.7 on Win 7, Office 2010 (v14), and a very recent stable
release of pywin (pywin32-216.win32-py2.7).

Code to recreate the problem:

app = Dispatch("Excel.Application")
app.Visible=True
books=app.Workbooks
books.Open(Filename="C:/temp/test.xlsx")
app.GetSaveAsFilename(InitialFilename="filename.xlsx")  # <<<<<<< THIS
PARAMETER IS IGNORED
app.Quit()

Pywin generated function for the GetSaveAsFilename function (in which it can
be seen that the parameter InitialFilename is handled):

def GetSaveAsFilename(self, InitialFilename=defaultNamedOptArg,
FileFilter=defaultNamedOptArg, FilterIndex=defaultNamedOptArg,
Title=defaultNamedOptArg
, ButtonText=defaultNamedOptArg):
return self._ApplyTypes_(1076, 1, (12, 0), ((12, 17), (12, 17), (12, 17),
(12, 17), (12, 17)), u'GetSaveAsFilename', None,InitialFilename
, FileFilter, FilterIndex, Title, ButtonText)

At the moment, development is stopped in its tracks, so comments are greatly
appreciated.

Thanks

Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20110713/c0173b52/attachment.html>


More information about the python-win32 mailing list