Automatically save file as value in cell A1?

samilynn

Board Regular
Joined
Jun 24, 2003
Messages
171
Office Version
  1. 2016
Platform
  1. Windows
Is it possible to automatically save a file (in a specified folder), as the value in cell A1?

I am trying to prevent the situation when a user enters important information in a file, but then forgets to save it.

So what if I automatically saved the file as the value in cell A1 (which would typically be a name) as soon as he types something in that cell, and then I would force an autosave every 1 minute or so?

Thanks for your help!!

Samantha
 

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.
Another option is to set the save every 1 minute:


1723834329399.png
 
Upvote 0
Try the following:

1. In the events of the sheet where you have the cell with the file name, put the following code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address(0, 0) = "A1" Then
    If Target.Count > 1 Then Exit Sub
    If Target.Value = "" Then Exit Sub
    
    Call SavingFile
    
  End If
End Sub
Note Sheet Event:
Right click the tab of the sheet you want this to work, select view code and paste the code into the window that opens up


2. In a module, put the following code.
  • Set "C:\work\files\" for your specific folder.
  • Set "Sheet1" by the name of your sheet
  • Set "00:01:00" by duration, for example "00:01:00" for one minute, "00:05:00" for every 5 minutes, etc.
  • If you want autosave to end, simply delete cell A1.

VBA Code:
Sub SavingFile()
  Application.DisplayAlerts = False
  If Sheets("Sheet1").Range("A1").Value = "" Then
    Exit Sub
  End If
  ThisWorkbook.SaveCopyAs "C:\trabajo\files\" & Sheets("Sheet1").Range("A1").Value & ".xlsm"
  Application.OnTime Now + TimeValue("00:01:00"), "SavingFile", , True
End Sub


----- --
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
----- --
 
Upvote 0
Try the following:

1. In the events of the sheet where you have the cell with the file name, put the following code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address(0, 0) = "A1" Then
    If Target.Count > 1 Then Exit Sub
    If Target.Value = "" Then Exit Sub
   
    Call SavingFile
   
  End If
End Sub
Note Sheet Event:
Right click the tab of the sheet you want this to work, select view code and paste the code into the window that opens up


2. In a module, put the following code.
  • Set "C:\work\files\" for your specific folder.
  • Set "Sheet1" by the name of your sheet
  • Set "00:01:00" by duration, for example "00:01:00" for one minute, "00:05:00" for every 5 minutes, etc.
  • If you want autosave to end, simply delete cell A1.

VBA Code:
Sub SavingFile()
  Application.DisplayAlerts = False
  If Sheets("Sheet1").Range("A1").Value = "" Then
    Exit Sub
  End If
  ThisWorkbook.SaveCopyAs "C:\trabajo\files\" & Sheets("Sheet1").Range("A1").Value & ".xlsm"
  Application.OnTime Now + TimeValue("00:01:00"), "SavingFile", , True
End Sub


----- --
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
----- --
Thank you so much, that is amazing!!!! Thank you thank you!

One more (last) question: can you think of a way that when the user is done entering data on the file, I can "force" a final "save" on it? Maybe with a button or something....so your code creates the files, with the filename that is in cell A1, which is AMAZING, but as the user keeps entering, it looks like's he's still working on the original file. I'd like to make sure he saves the file that's in the new folder when he is done entering. The only way I can think to do that is to change the timer in the code to 00:00:01, but wouldn't that cause performance issues, if it keeps saving every one second?
 
Upvote 0
I'd like to make sure he saves the file that's in the new folder when he is done entering.
Replace this line:

VBA Code:
ThisWorkbook.SaveCopyAs "C:\trabajo\files\" & Sheets("Sheet1").Range("A1").Value & ".xlsm"


For this:

VBA Code:
ThisWorkbook.SaveAs "C:\trabajo\files\" & Sheets("Sheet1").Range("A1").Value & ".xlsm"

🤗
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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