Using vba to save a file without a password

rammi125

New Member
Joined
Jun 3, 2015
Messages
22
I have a file that has a password on it. To save the file without a password I click save as and then next to save choose tools, general options, delete the password that's already there and then save the workbook.

What's the VBA code to do the above so that the file gets saved without a password? My code is below:


COLLATERALfile = "\\Nas01\shared\RSH\TECH\Operations\Futures Ops\Archive\Futures Pledged Collateral Report " & _
Format(Date, "mm.dd.yy") & ".xlsx"

Workbooks.Open COLLATERALfile, Password:="Agico6nm"

ActiveWorkbook.SaveAs Filename:= _
"\\us1.1corp.org\NY1\Users\RSingh\Documents\Download #2 - Futures Pledged Collateral Report.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False, WriteresPassword:=""




Set COLLATERALBook = ActiveWorkbook

COLLATERALBook.Close savechanges:=False
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
When you click Save as > Tools > General Options there are two passwords that can be set or cleared. One to open the workbook, one to modify the workbook.
Your current code is just clearing the latter with WriteresPassword:="". To clear the password that allows opening of the workbook, use Password:=""

Code:
ActiveWorkbook.SaveAs Filename:= _
 "\\us1.1corp.org\NY1\Users\RSingh\Documents\Download #2 - Futures Pledged Collateral Report.xlsx" _
 , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False, WriteresPassword:="", [B]Password:=""[/B]
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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