Save As Cell content

Shang_7

New Member
Joined
Jul 24, 2018
Messages
9
I currently have the Save blocked to where you can only do a Save As.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Not SaveAsUI Then
Cancel = True
End If
End Sub


But I also am wanting when you go to Save As it will have the contents from Sheet "Data" B3 in the filename. I do not care to add the file save location, I only want to add the filename from B3 in .xlsm format. Is that possible to have the name automatically placed in the filename when you click on File/Save As?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi,

This code would save a file with name in B3 in the same location.
Code:
Dim DynamicFileName As String
DynamicFileName = Worksheets("Data").Range("B3").Value
ActiveWorkbook.SaveAs Filename:=DynamicFileName

Of course you have to consider you can not save as twice with the same name (I receive a message if I want to replace the existing file)
 
Last edited:
Upvote 0
It didn't work for me. Maybe I am putting it in the wrong place. I have tried many things and it hasn't worked.
 
Upvote 0
It didn't work for me. Maybe I am putting it in the wrong place. I have tried many things and it hasn't worked.

Here is what I did:

-Open a new 2016 excel document
-Rename Sheet1 by Data
-Write Exact in cell B3
-Save the file as Book1.xlsm (macro enabled workbook) on my desktop
-Open VBA and insert a module (module1)
-Write
Code:
 Sub Test()
Dim DynamicFileName As String
DynamicFileName = Worksheets("Data").Range("B3").Value
ActiveWorkbook.SaveAs Filename:=DynamicFileName
End Sub
-Run the macro Test and I got a file called Exact.xlsm on my desktop which is opened and Book1 is closed.

Hope it helps
 
Last edited:
Upvote 0
OK I understand now. I was actually hoping to be able to only go to File/SaveAs and the filename that would be there from cell B3 without having to click on run a macro, but rather automatic. Is there a way to do that?
 
Upvote 0
Simply put a button in the access toolbar or any ribbon that launches the macro (with a floppy disk icon for example)

Code:
Sub Saveas()
Application.GetSaveAsFilename Worksheets("Data").Range("B3").Value, "XLSM Files (*.xlsm), *.xlsm"
End Sub

FYI but I do not recommend it, in VBA, there are "events" that can launch macro. For example, it is possible to launch the macro every time the workbook opens, close, you change a sheet, before saving,... or even change the value of this specific cell.

Not only having this macro automatically launch when changing the value of B3 will impact the speed response of the file but the must annoying is that everytime you change the value of the cell, you lose the "undo" function.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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