Read-only file: Cannot save it with VBA code

chrisignm

Active Member
Joined
Apr 1, 2014
Messages
273
Hi, what I'm trying to do:

I have a read-only file. I want to save the file AFTER I did some changes to it.

I got a VBA code, but it only works if the file is 100% the same (no changes were made):

Code:
Sub SaveAfterUpdate()
If ActiveWorkbook.ReadOnly Then
With ActiveWorkbook
        SetAttr .FullName, vbNormal
        .ChangeFileAccess Mode:=xlReadWrite, WritePassword:="admin"
 
        Application.DisplayAlerts = False
        .Save
        Application.DisplayAlerts = True
        .ChangeFileAccess Mode:=xlReadOnly, WritePassword:="admin"
    End With
Else
With ActiveWorkbook
Application.DisplayAlerts = False
        .Save
Application.DisplayAlerts = True
.ChangeFileAccess Mode:=xlReadOnly, WritePassword:="admin"
End With
End If
End Sub

Could somebody please tell me how to save the read-only file also when I made changes? (and save as read-only again!)

Reason: Part of an automatized update routine

edit: The problem is basically that I can't remove read-only If I changed something within the file.

Thanks alot :)
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,216,028
Messages
6,128,395
Members
449,446
Latest member
CodeCybear

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