Save as with calculated filename - VBA

Vispon

New Member
Joined
Jul 12, 2010
Messages
20
Hi everyone, I've found a few different threads on the elements of this but I haven't been able to cobble them together, hoping you may be able to help.

I'm looking to run a command which will
  • open the save as dialogue on screen
  • Defaultly fill the file name with 'INV_TRC_[cel c1]_[current date time as DDMMYYYYHHMMSS]
  • file type CSV

I came across the below which does some of it but I'm having trouble piecing it all together :/

Code:
[COLOR=#2D4050][FONT='inherit']Sub SaveUnique() 
'
' Save a file with a unique name 
' 
ActiveWorkbook.SaveAs Filename:="C:\Temp\Book" & Format(Now(), "yyyymmddhhmmss") & ".xlsx", _ 
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False 
End Sub[/FONT][/COLOR]
 
Last edited:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Does this do what you want?

Code:
Sub savecsv()
myfilename = "INV_TRC_" & Range("c1") & "_" & Format(Now(), "DDMMYYYYHHMMSS")
Filename = Application.GetSaveAsFilename(InitialFileName:=myfilename, fileFilter:="csv Files (*.csv), *.csv")

End Sub
 
Upvote 0
Thanks Scott

That brings up the save dialogue with the file name perfectly.
The only odd issue I'm having is when I then click save the file doesn't seem to actually be saved in the destination?
 
Upvote 0
Try this.


Code:
Sub savedi()
myfilename = "INV_TRC_" & Range("c1") & "_" & Format(Now(), "DDMMYYYYHHMMSS")
Filename = Application.GetSaveAsFilename(InitialFileName:=myfilename, fileFilter:="csv Files (*.csv), *.csv")
ActiveWorkbook.SaveAs Filename:=Filename

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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