Save copy as protected and macro free

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
I'm trying to save a copy of the activeworkbook as an xlsx macro free file, read only and protected but I can't get this to work:

VBA Code:
SaveName = Left$(ThisWorkbook.Name, InStrRev(ThisWorkbook.Name, ".") - 1) & " (Read Only).xlsx"


ActiveWorkbook.SaveCopyAs Filename:=ThisWorkbook.Path & "\" & SaveName

 SavedFile = ThisWorkbook.Path & "\" & SaveName

SavedFile.Protect Structure:=True, Windows:=False, Password:=""
 VBA.SetAttr ThisWorkbook.Path & "\" & SaveName, vbNormal

It saves the file, but I'm getting an error 424 Object Required on this line:

VBA Code:
SavedFile.Protect Structure:=True, Windows:=False, Password:="password"

Can anyone advise what the problem is?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Is the activeworkbook an xlsx file?
 
Upvote 0
Cheers Fluff, no, the workbook this is being run from is an xlsm file.
 
Upvote 0
In that case you cannot use Savecopyas, as it doesn't allow you to change the file format.
 
Upvote 0
Ahh, ok, didn't realise that - is there any way I can save a macro-free version then?
 
Upvote 0
How about
VBA Code:
Sub sharky()
   Dim Fname As String
   With ThisWorkbook
      Fname = Left(.FullName, InStrRev(.FullName, ".") - 1)
      Application.DisplayAlerts = False
      .SaveAs Fname, 51, , , True
      Application.DisplayAlerts = True
   End With
   With ActiveWorkbook
      .Protect , True, False
      .Save
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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