VBA save duplicate on close question

piersm2

New Member
Joined
Mar 1, 2019
Messages
2
I am having an issue with my save copy on close VBA code. I am wanting to save a OneDrive shared file (which is a .xlsb file type) upon closing the file to a network drive, but am wanting to save it as a .xlsx file, not .xlsb file type. If I use this code, the file will save, but I get an error when I try to open the duplicate file saying that it is the wrong file type. If I change it to save as a .xlsb file type, it works. I am wanting to save a regular excel workbook, not a macro workbook. Can anyone assist me?

Private Sub Workbook_BeforeClose(Cancel As Boolean)
With ThisWorkbook
Application.DisplayAlerts = False
.SaveCopyAs Filename:="J:\folder1\folder2\afilename.xlsb"
Application.DisplayAlerts = True
End With
End Sub
 
Last edited by a moderator:

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Welcome to the Board!

Is this VBA code in the workbook you are trying to save? If so, then you cannot save it as an "xlsx" file, as that extension denotes that it is a Macro-free workbook.
All files with macros should be saved with "xlsm" or "xlsb".
 
Upvote 0
Is there a way to save it as a Macro-free workbook? I want the macro in the working document, but not the duplicate that is saved.
 
Upvote 0
You can have your VBA copy the data over to a new, blank workbook, and save that.
You can get a lot of the code you need for that using the Macro Recorder. If you need help cleaning up that code and adding to it, post it here and let us know.
 
Upvote 0

Forum statistics

Threads
1,215,110
Messages
6,123,138
Members
449,098
Latest member
Doanvanhieu

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