Excel Excel Macro how to prompt for save name

Joined
Jul 7, 2011
Messages
2
Reaction score
0
Appreciate a little help for a macro novice. Simple macro.
Sheets("SPA").Select
Sheets("SPA").Copy
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ChDir "C:\Documents and Settings\me\Desktop"
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\me\Desktop\SPA.xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
Application.WindowState = xlMinimized
Windows("PC 2011 Oct master.xls").Activate
End Sub

What and where do I enter a routine to prompt for the save file name. Presently it always save as SPA.xls I would like to be prompted to enter the name. I've seen threads on this but can't get it right. I need someone to say exactly where and what to enter.

Thank you in advance.
 
Joined
Aug 30, 2011
Messages
5
Reaction score
0
After this line:
ChDir "C:\Documents and Settings\me\Desktop"

Add the following:

fileName = Application.GetSaveAsFilename
If filename <> False Then

' the name of the file chosen by the user will be stored in fileName
<put your code to save the file here>

End If


Don't forget to add this line at the top of the macro:
Dim fileName as Variant

Hope this helps.

Rajeev
 

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

Simplify save code 11
Save with ref. to cell A1 2
Save As Macro 2
save & backup file 2
Save as marco 3
create a workbook 1
Saving a workbook to an iKnow portal 2
Macro syntax "Save As" with filename from cell ref. 1

Top