SaveAs Question

Leeray

Board Regular
Joined
Apr 2, 2009
Messages
64
Attached is the following Saveas macro that I have.

Basically it does what I want. I push a button, the Save As option comes up, the Path is 99% there (Each file has 1 addtional step which must be done manually!) and I get to choose the file name.
Everything works now, no little nasty error codes Great :biggrin:.

However I would like to take this a step further and fill the Filename using a cell on the worksheet. I do not however want the file to automatically save as I need to go one step further in allocating the correct path (As stated earlier).

Is this possible?

I would also like to add todays date at the front of the filename.

Let me know what you think


Private Sub CommandButton2_Click()
ChDrive "S"
ChDir "S:\Activity\LONDON REGIONAL 992\ACTIVE ACCOUNTS"

fileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Excel Files (*.xls), *.xls")

If fileSaveName <> False Then
On Error Resume Next
ActiveWorkbook.SaveAs Filename:=fileSaveName, FileFormat:=xlNormal
ActiveWorkbook.Close

End If

End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi,

Are you after something like this?

Code:
ActiveWorkbook.SaveAs Filename:=Range("A1") & ".xls", FileFormat:=xlNormal
ActiveWorkbook.Close False
 
Upvote 0
You could use the SaveAs dialog and prepopulate the name. The following example will default the name to the date formatted as DDMMYY

Code:
Application.Dialogs(xlDialogSaveAs).Show (Format(Date, "DDMMYY"))
 
Upvote 0
I have now figured out the date part in excel but thank-you Jon Von der Heyden.

My code now reads

Private Sub CommandButton2_Click()
ChDrive "S"
ChDir "S:\Activity\LONDON REGIONAL 992\ACTIVE ACCOUNTS"
'Retrieve file name to use for Save
fileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Excel Files (*.xls), *.xls")
'If user specified file name, perform Save and display msgbox
If fileSaveName <> False Then
On Error Resume Next
ActiveWorkbook.SaveAs Filename:=Range("E85") & ".xls", FileFormat:=xlNormal
ActiveWorkbook.Close False

End If

End Sub


It's odd as that when I hit the command button the filename appears as the original name of the file but when I click save it saves as the name in the cell (which I want!). Is there any way to display the cell name in the display saveas option?

thanks in advance
 
Upvote 0
OK looks like I've cracked it.
I've had a dabble with a different code and it seems to do what I want without any errors.

Code is:

Private Sub CommandButton2_Click()
ChDrive "S"
ChDir "S:\Activity\LONDON REGIONAL 992\ACTIVE ACCOUNTS"

With Sheet1
sFileName = .Range("E85").Text
sFileName = Application.GetSaveAsFilename(sFileName, "Excel Files (*.xls), *.xls")
If sFileName <> "False" Then
On Error Resume Next
Application.EnableEvents = False
ThisWorkbook.SaveAs sPath & sFileName
Application.EnableEvents = True
End If

End With
ActiveWorkbook.Close False
End Sub


I push a button, it opens up the saveas menu, the saveas path is where I want it to be, the filename is populated from a cell, I click save and hey presto it saves. There are no errors what so ever. Oh and the file then closes as I wanted.

Many thanks for your help
 
Upvote 0

Forum statistics

Threads
1,214,547
Messages
6,120,139
Members
448,948
Latest member
spamiki

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