Prompt user to save their file

S

Sharon

I am trying to prompt the user to save their file.

Application.GetSaveAsFilename looks like the right window
that pops up but the file doesn't actually save.

I tried this: ActiveWorkbook.SaveAs(Filename:=fName)
thinking I could set up a variable but maybe I have the
syntax wrong because it is not working.

Any ideas?
Thanks,
Sharon
 
J

Jake Marx

Hi Sharon,

You're correct - GetSaveAsFilename will only return the filename, if any,
the user selected; it won't actually save the file. So you have to do that:

Dim vPath As Variant

vPath = Application.GetSaveAsFilename(FileFilter:= _
"Microsoft Excel Files (*.xls), *.xls")

If vPath <> False Then
ActiveWorkbook.SaveAs vPath
End If
 
S

Sharon

I see then, I don't need to use "Filename:=" if I'm using
a variable. Thanks so much!
One more question if you don't mind.
It's about "Dim vPath As Variant"
I'm still learning about variables - so I wonder is it
better to use Variant than String?
Thanks for the info -
Have a great weekend.
Sharon
 
D

Dave Peterson

The filename:= is optional--as long as you put the filename as the first
parameter.

Some people like it, some don't always use it. I think it makes it easier
reading code.

But Jake dimmed vPath as variant so that he could use it as a string (if the
user selected a file) or use it as a boolean (when he compared it to False).
 
S

Sharon

Oh I see. Sometimes I am so literal. I didn't try
filename:= variableName. I think it is easier to read
also.

Thanks for that note about using "Variant" so it could be
used as boolean when comparing to False. I didn't realize
that.
Thanks-
Sharon
 

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

Similar Threads


Top