Save As Macro Enabled Workbook

CC268

Active Member
Joined
Mar 7, 2016
Messages
328
Hey guys,

I would like to create a VBA code that simply opens the Save As dialog window (in order to type your desired file name) and saves it as a Macro Enabled Workbook.

Thanks
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Without seeing your code, wouldn't be able to comment... maybe you're calling the dialog box twice? Maybe it's inside a loop? Maybe you have other code that's causing the second window to pop open?
 
Upvote 0
Without seeing your code, wouldn't be able to comment... maybe you're calling the dialog box twice? Maybe it's inside a loop? Maybe you have other code that's causing the second window to pop open?

Code:
Dim tDate As String
Dim FileSaveName As String
Dim fName As String


fName = ActiveWorkbook.FullName
tDate = VBA.Format(DateSerial(Year(Date), Month(Date), Day(Date)), "dd-mm-yyyy")
FileSaveName = Application.GetSaveAsFilename(InitialFileName:=fName, filefilter:="Excel Files(*.xlsm),*.xlsm", Title:="Please save the file")
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
ActiveWorkbook.SaveAs Filename:=fName & tDate & ".xlsm", FileFormat:=52
End With

I want it to pop open and use the current file name plus add the current date (10-10-2017). I am close but not quite there. Also if I press save or cancel the same window pops open again regardless. Not sure why.
 
Upvote 0
Parts in blue creates pop-up windows, your code is calling a pop-up window twice:
Rich (BB code):
fileSaveName = Application.GetSaveAsFilename(InitialFileName:=fname, filefilter:="Excel Files(*.xlsm),*.xlsm", Title:="Please save the file")
With Application.FileDialog(msoFileDialogFolderPicker)
I think you can reduce your code to:
Rich (BB code):
Dim tDate As String
Dim FileSaveName As String
Dim fName As String


fName = ActiveWorkbook.FullName & "_" & Format(today, "DD-MM-YYYY")
FileSaveName = Application.GetSaveAsFilename(InitialFileName:=fName, filefilter:="Excel Files(*.xlsm),*.xlsm", Title:="Please save the file")
ActiveWorkbook.SaveAs FileName:=FileSaveName, FileFormat:=52
 
Last edited:
Upvote 0
Parts in blue creates pop-up windows, your code is calling a pop-up window twice:
Rich (BB code):
fileSaveName = Application.GetSaveAsFilename(InitialFileName:=fname, filefilter:="Excel Files(*.xlsm),*.xlsm", Title:="Please save the file")
With Application.FileDialog(msoFileDialogFolderPicker)
I think you can reduce your code to:
Rich (BB code):
Dim tDate As String
Dim FileSaveName As String
Dim fName As String


fName = ActiveWorkbook.FullName & "_" & Format(today, "DD-MM-YYYY")
FileSaveName = Application.GetSaveAsFilename(InitialFileName:=fName, filefilter:="Excel Files(*.xlsm),*.xlsm", Title:="Please save the file")
ActiveWorkbook.SaveAs FileName:=FileSaveName, FileFormat:=52

Thanks for the help. That makes sense when I step into the code and run it line by line. Two things:

1. Is there any way to have it add the current date (10-10-2017) to the end of the file name when you name it?
2. If I press the cancel button it still saves the file, but saves it as "False.xlsm". How can I make it just not do anything if I press the cancel button?

Thanks
 
Last edited:
Upvote 0
Untested (again!), try:
Rich (BB code):
Dim tDate As String
Dim FileSaveName As String
Dim fName As String

fName = ActiveWorkbook.FullName & "_" & Format(today, "DD-MM-YYYY")
FileSaveName = Application.GetSaveAsFilename(InitialFileName:=fName, filefilter:="Excel Files(*.xlsm),*.xlsm", Title:="Please save the file")
if FileSaveName <> FALSE Then ActiveWorkbook.SaveAs FileName:=fName, FileFormat:=52
 
Last edited:
Upvote 0
Untested (again!), try:
Rich (BB code):
Dim tDate As String
Dim FileSaveName As String
Dim fName As String

fName = ActiveWorkbook.FullName & "_" & Format(today, "DD-MM-YYYY")
FileSaveName = Application.GetSaveAsFilename(InitialFileName:=fName, filefilter:="Excel Files(*.xlsm),*.xlsm", Title:="Please save the file")
if FileSaveName <> FALSE Then ActiveWorkbook.SaveAs FileName:=fName, FileFormat:=52

Bummer...that didn't work:

1. No file name shows up in Save As window - it just blank - have to type in the file name yourself or select one from current folder
2. It didn't like
Code:
if FileSaveName <> FALSE Then
as it gave me a "Run-time error 13: Type mismatch"
 
Upvote 0
Why do you need the pop-up window? You could save it directly since you're using the Activeworkbook's full name:
Code:
Dim fName As String

fName = ActiveWorkbook.FullName & "_" & Format(today, "DD-MM-YYYY") & ".xlsm"

' FileSaveName = Application.GetSaveAsFilename(InitialFileName:=fName, filefilter:="Excel Files(*.xlsm),*.xlsm", Title:="Please save the file")
' If FileSaveName <> False Then ActiveWorkbook.SaveAs FileName:=fName, FileFormat:=52

ActiveWorkbook.SaveAs FileName:=fName, FileFormat:=52
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,891
Messages
6,175,229
Members
452,621
Latest member
Laura_PinksBTHFT

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