VBA Code for Saving Workbook not working

WxShady13

Board Regular
Joined
Jul 24, 2018
Messages
185
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I am creating an Archive macro that when pressed will send a worksheet from one workbook to another. Currently the code will open the workbook and send the worksheet and then delete it from the original workbook. The problem I am having is saving the destination workbook after it has been opened. It is named CMD-Archive and sits in a Doc Library on a SharePoint site where the source file sits. What am I doing wrong?

Code:
Sub Archive()
'Application.AskToUpdateLinks = False
Application.DisplayAlerts = False
Workbooks.Open "FILENAME", UpdateLinks = False

ThisWorkbook.ActiveSheet.Copy After:=Workbooks("CMD-Archive.xlsm").Sheets(1)
Workbooks("CMD-Archive.xlsm").Activate
Application.DisplayAlerts = False
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.DisplayAlerts = True

Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True

End Sub
 
Last edited:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi, when you run this code, is the CMD-Archive workbook saving at all or does it just close? Does it give an error?
 
Upvote 0
When the DisplayAlerts = False is turned off I get the popup asking me to save it, however when it is True I do not see anything, nor does it save. It does delete the worksheet from the source file though.
 
Upvote 0
I was not able to recreate the issue you are having. On a different note, you do not need to continue setting DisplayAlerts to true or false after it is done once as it applies to the application, not a specific workbook. To clean it up a bit, it could look like this:

Code:
Sub Archive()
'Application.AskToUpdateLinks = False
Application.DisplayAlerts = False
Workbooks.Open "FILENAME", UpdateLinks = False


ThisWorkbook.ActiveSheet.Copy After:=Workbooks("CMD-Archive.xlsm").Sheets(1)
Workbooks("CMD-Archive.xlsm").Activate
ActiveWorkbook.Save
ActiveWorkbook.Close


ActiveSheet.Delete


Application.DisplayAlerts = True


End Sub

This shouldn't effect what your code does, but it definitely cleans it up a bit.
 
Upvote 0
THANK YOU!!! I wonder if it has anything to do with writing it back to a SharePoint site versus a shared folder?
 
Upvote 0
THANK YOU!!! I wonder if it has anything to do with writing it back to a SharePoint site versus a shared folder?

I'm not incredibly familiar with how a SharePoint site works so I am unsure. From what I understand though (and this could be completely wrong), isn't a SharePoint site treated very similar to a shared folder by Excel when trying to save a file to the folder? For example, you could just save as anything to the SharePoint site as if it were a folder?
 
Upvote 0
In some cases....Thank you for the code, I think the disconnect now is between Excel and SP. I will continue working to see why they are not auto saving. I truly appreciate the help
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,239
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