GetSaveAsFilename - file name is blank

J

JanetJek

I have an Excel macro that prompts the user for the file name with
GetSaveAsFilename. It works fine under Window XP (Excel 2000, 2003, 2007)
but with Excel 2007 and Vista, the file name in the prompt box is empty,
blank. There is no file name.

Any suggestions?
 
R

Ron de Bruin

Hi Janet

This is working for me in Vista/O2007

Dim fname As Variant
fname = Application.GetSaveAsFilename(InitialFileName:="test.xlsm", _
fileFilter:="Excel Files (*.xlsm), *.xlsm")
 
R

Rick Rothstein \(MVP - VB\)

It looks like if you do not provide the FileFilter argument, the InitialFile
argument is ignored. This, of course, is different than with XL2003.

Rick
 
R

Rick Rothstein \(MVP - VB\)

Remove the fileFilter argument and you will see what the OP is writing
about... apparently XL2007 changed something as XL2003 works fine with just
the InitialFile argument.

Rick
 
R

Rick Rothstein \(MVP - VB\)

And, of course, it makes good sense to **always** use FileFilter (OP please
take note)... I am not sure why Microsoft decided to change
GetSaveAsFilename in XL2007 making the display of InitialFile contingent on
its use though.

Rick
 
J

JanetJek

Thanks Rick and Ron, you saved my day.
And I'll certainly use FileFilter from now on!
 
S

Stephen

Thanks for the heads up Ron,

However; I have that code implemented, but I am receiving an error message
(file format or extension) when I try to re-open the file.

Any thoughts? Thanks ~ Stephen

here is the code on 1 line ...

fName = Application.GetSaveAsFilename(InitialFileName:="test.xlsm",
FileFilter:="Excel Files (*.xlsm), *.xlsm")
 
C

Charlie Hall

The situation is more bizarre than presented. I was still getting the problem even with using filefilters argument

I was trying to save an xlt file with the following:

filefilter:="Template (*.xlt; *.xltm; *.xltx), *.xlt; *.xltm; *.xltx"

This works perfectly well on XL 2003. However on 2007 the initial filename would be blank

I discovered after some time that the initial filename extension must match the final file filter before it will be displayed

so this works on 2007:

filefilter:="Template (*.xltx; *.xltm; *.xlt), *.xltx; *.xltm; *.xlt"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top