Auto save as

aliaslamy2k

Active Member
Joined
Sep 15, 2009
Messages
416
Office Version
  1. 2019
Platform
  1. Windows
I have a workbook which will be updated by multiple users everyday ( SHARED WORKBOOK), I have created a copy of same in my system( NOT SHARED) and I need it to get updated every time when user updates.

Eg: Save - workbook name as master copy in (location D:\)


Thanks in advance

Rgds,
AB
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Put this in your shared workbook.... open shared workbook, press Alt+F11, on the left double click ThisWorkbook and paste this code

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Application.DisplayAlerts = False ' eliminates replace existing file dialog
    ActiveWorkbook.SaveAs ("D:\MyFilepath\xlFileName.xls")
    Application.DisplayAlerts = True ' turn alerts back on
End Sub
 
Upvote 0
Actually no.... this will save the shared workbook over your non-shared workbook in your file location.... then when the user goes to save, it will save in your location, not the shared's location.... hold on, revised edition coming....
 
Upvote 0
Thanks a ton dear for looking into this matter.


Kind Regards,
AB:confused:
 
Upvote 0
Hello experts,

Can anyone help me to get solution of this puzzle

Kind rgds,
AB:confused:
 
Upvote 0
This code works... go into shared workbook, press Alt+F11, double-click ThisWorkbook, and paste the following code:

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If ActiveWorkbook.FullName = "C:\SharedPath\SharedWBook.xls" Then
        Dim originalFilename As String
        originalFilename = "C:\SharedPath\SharedWBook.xls"
        Application.DisplayAlerts = False
        ActiveWorkbook.SaveAs ("D:\MasterFilePath\MasterWBook.xls")
        ActiveWorkbook.SaveAs (originalFilename)
        Application.DisplayAlerts = True
    End If
End Sub

You MIGHT have Excel close due to an error rarely... or at least I did. I tried remedying this by putting the IF statement in. Basically, if you save the shared workbook, it will first save as the master copy, but since the code is the same, before it saves the master, it might save the master, then run the code again, etc. etc... so to avoid looping, only your shared workbook will go and make a copy over the master workbook.

If you make a change to the master and save, it will not save over the shared workbook.
 
Upvote 0
This disables events before running the code... maybe that way when Shared saves itself as Master, the save to master won't trigger the "BeforeSave" method, however I'm still getting a crash. Anyone know what's up?

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If ActiveWorkbook.FullName = "S:\SharedPath\SharedWBook.xls" Then
        Application.EnableEvents = False
        Dim originalFilename As String
        originalFilename = "S:\SharedPath\SharedWBook.xls"
        
        Application.DisplayAlerts = False
        ActiveWorkbook.SaveAs ("D:\MasterPath\MasterWBook.xls")
        ActiveWorkbook.SaveAs (originalFilename)
        Application.DisplayAlerts = True
        
        Application.EnableEvents = True
        
    End If
End Sub
 
Upvote 0
Dear Paipimenta,

Highly appreciate your efforts on this puzzle, Can anyone please help us solve this issue?


Rgds,
AB
 
Upvote 0
Fixed!!!! Thanks Richard Schollar!
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If ActiveWorkbook.FullName = "S:\SharedPath\SharedWBook.xls" Then
 
        Application.EnableEvents = False
        Application.DisplayAlerts = False
 
        ActiveWorkbook.SaveCopyAs ("D:\MasterPath\MasterWBook.xls")
 
        Application.DisplayAlerts = True
        Application.EnableEvents = True
 
    End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,458
Members
449,085
Latest member
ExcelError

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