Save workbook to a specific location and override file with same name.

Blanchetdb

Board Regular
Joined
Jul 31, 2018
Messages
153
Office Version
  1. 2016
Platform
  1. Windows
Hello

I am looking to use a command button that will save a workbook to specific location.

The Workbook is updated daily by the user and when they save, it needs to override the previous information (saved information) and NOT save as a new workbook.

I have tried various methods suggested in previous posts but unsuccessfully.

this is the path of where the document needs to be saved: C:\Users\blanchetdb\AppData\Roaming\OpenText\DM\Temp\CFIA_ACIA-#20398545-v1-test_database.XLSM

any help would be greatly appreciated.

thank you
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
If you want the workbook to keep the same name it currently has, where ever it was opened from, you can use:
VBA Code:
Application.Displayalerts = False
ThisWorkbook.SaveCopyAs "C:\Users\blanchetdb\AppData\Roaming\OpenText\DM\Temp\CFIA_ACIA-#20398545-v1-test_database.XLSM"
Application.Displayalerts = True
Alternatively you can use this (which changes the workbook to the saved name and location):
VBA Code:
Application.Displayalerts = False
ThisWorkbook.SaveAs "C:\Users\blanchetdb\AppData\Roaming\OpenText\DM\Temp\CFIA_ACIA-#20398545-v1-test_database.XLSM", xlOpenXMLWorkbookMacroEnabled
Application.Displayalerts = True
 
Upvote 0
If you want the workbook to keep the same name it currently has, where ever it was opened from, you can use:
VBA Code:
Application.Displayalerts = False
ThisWorkbook.SaveCopyAs "C:\Users\blanchetdb\AppData\Roaming\OpenText\DM\Temp\CFIA_ACIA-#20398545-v1-test_database.XLSM"
Application.Displayalerts = True
Alternatively you can use this (which changes the workbook to the saved name and location):
VBA Code:
Application.Displayalerts = False
ThisWorkbook.SaveAs "C:\Users\blanchetdb\AppData\Roaming\OpenText\DM\Temp\CFIA_ACIA-#20398545-v1-test_database.XLSM", xlOpenXMLWorkbookMacroEnabled
Application.Displayalerts = True
thank you for the reply

when I try the first code, I get:
1704292418190.png


When I try the second code; It looks like it is saving (somewhere) but it didn't override the previous saved document with the same name. Our department uses a repository to save all documents and it sometimes causes issues (this may be the case here). I provided the correct location of the document within repository.
 
Upvote 0
In that case, please try this:

VBA Code:
Application.Displayalerts = False
On Error Resume Next
Kill "C:\Users\blanchetdb\AppData\Roaming\OpenText\DM\Temp\CFIA_ACIA-#20398545-v1-test_database.XLSM"
On Error Goto 0
DoEvents
If Len(Dir("C:\Users\blanchetdb\AppData\Roaming\OpenText\DM\Temp\CFIA_ACIA-#20398545-v1-test_database.XLSM")) > 0 Then
    MsgBox "Unable to remove old copy of the file!"
Else
    ThisWorkbook.SaveAs "C:\Users\blanchetdb\AppData\Roaming\OpenText\DM\Temp\CFIA_ACIA-#20398545-v1-test_database.XLSM", xlOpenXMLWorkbookMacroEnabled
End If
Application.Displayalerts = True
 
Upvote 0
In that case, please try this:

VBA Code:
Application.Displayalerts = False
On Error Resume Next
Kill "C:\Users\blanchetdb\AppData\Roaming\OpenText\DM\Temp\CFIA_ACIA-#20398545-v1-test_database.XLSM"
On Error Goto 0
DoEvents
If Len(Dir("C:\Users\blanchetdb\AppData\Roaming\OpenText\DM\Temp\CFIA_ACIA-#20398545-v1-test_database.XLSM")) > 0 Then
    MsgBox "Unable to remove old copy of the file!"
Else
    ThisWorkbook.SaveAs "C:\Users\blanchetdb\AppData\Roaming\OpenText\DM\Temp\CFIA_ACIA-#20398545-v1-test_database.XLSM", xlOpenXMLWorkbookMacroEnabled
End If
Application.Displayalerts = True
I got the message saying that it was unable to remove the old file ... which doesn't solve my issue
 
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,235
Members
449,092
Latest member
SCleaveland

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