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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
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,215,444
Messages
6,124,891
Members
449,194
Latest member
JayEggleton

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