Saving a file with macro

DaKen

Board Regular
Joined
Feb 18, 2002
Messages
55
I have a spreadsheet that pulls info from a database. I want to add a macro to save the file, with the file name being the contents of a cell in the sheet. I want to use an input box though, with the contents of that cell as the suggested input(similar to the save as box). That way the user can change it if necessary.
This message was edited by DaKen on 2002-02-19 09:08
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Can the contents of a cell be placed in the file name input section?
This message was edited by DaKen on 2002-02-19 09:33
 
Upvote 0
How's this:

fname = InputBox("Name the file", "Howdy", Range("a1") & ".xls")
If fname<> "" Then
ActiveWorkbook.saveas Filename:=fname
End If

Cheers,

Nate
This message was edited by NateO on 2002-02-19 11:37
 
Upvote 0
The answer to your second question is Yes. And it's better than using an input box:

Sub save_itas2()
fname = Application.GetSaveAsFilename _
(InitialFilename:=Range("a1"), _
FileFilter:="Excel Files (*.xls),*.xls", FilterIndex:=0, Title:="Save As")
If fname <> "False" Then
ActiveWorkbook.saveas Filename:=fname
End If

End Sub

Cheers,

Nate
 
Upvote 0
This worked great!! Is there any way to pull the date from a cell that is "=today()" in a format that can be saved as part of the file name?
 
Upvote 0
Why pull the date from a cell? How's this:

Sub save_itas3()
fname = Application.GetSaveAsFilename _
(InitialFilename:=Range("a1") & " " & WorksheetFunction.Substitute(Date, "/", "_"), _
FileFilter:="Excel Files (*.xls),*.xls", FilterIndex:=0, Title:="Save As")
If fname<> "False" Then
ActiveWorkbook.SaveAs Filename:=fname
End If
End Sub


Cheers,

Nate
This message was edited by NateO on 2002-02-19 20:13
 
Upvote 0
I tried that, but it returns 2/19/2002 which won't work. I'd have to get rid of the "/" somehow!
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,240
Members
448,555
Latest member
RobertJones1986

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top