Saving a copy of a protected workbook without a password

scotthannaford1973

Board Regular
Joined
Sep 27, 2017
Messages
115
Office Version
  1. 2010
Platform
  1. Windows
Hi

I have an .xlsm file that is password protected through SaveAs-->General Options as the file is always opened read only without the password.

I want to apply a macro to a button that will export a copy either the current worksheet, or the entire workbook to a specific location of H:/

the coding I usually use works absolutely fine for copying the file, but the copy always asks for the password - so I want to tweak my code so a password is not needed on that copy.

TIA
---------------------------------------------------------------------

Sub Auto_Save()
Dim savedate

savedate = Date

Dim savetime
savetime = Time
Dim formattime As String
formattime = Format(savetime, "hh.MM")
Dim formatdate As String
formatdate = Format(savedate, "YYYY.MM.DD")

Application.DisplayAlerts = False

Dim backupfolder As String
backupfolder = "H:"
ActiveWorkbook.SaveCopyAs Filename:=backupfolder & formatdate & " " & formattime & " " & ActiveWorkbook.Name
ActiveWorkbook.Save
Application.DisplayAlerts = True
MsgBox "CIP Tracker backed up to " & backupfolder & " - check folder if needed!"

End Sub

---------------------------------------------------------------------
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try this

Change "abc" for the password of your workbook.

Code:
Sub Auto_Save()
  Dim formatdate As String, formattime As String, backupfolder As String
  Application.DisplayAlerts = False
  Application.ScreenUpdating = False
  
  formatdate = Format(Date, "YYYY.MM.DD")
  formattime = Format(Time, "hh.MM")
  backupfolder = "H:" & formatdate & " " & formattime & " " & ThisWorkbook.Name
  
  ActiveWorkbook.SaveCopyAs Filename:=backupfolder
  Workbooks.Open Filename:=backupfolder, Password:="[B][COLOR=#ff0000]abc[/COLOR][/B]"
  ActiveWorkbook.SaveAs Filename:=backupfolder, Password:=""
  ActiveWorkbook.Close
  Application.DisplayAlerts = True
  MsgBox "CIP Tracker backed up to " & backupfolder & " - check folder if needed!"
End Sub
 
Upvote 0

Forum statistics

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