VBA to save a file that was opened as read only

LSM1604

New Member
Joined
Jan 8, 2010
Messages
49
Hey,

I would like some code that changes the workbook to Attr - normal, then to save it. However I get an error message saying that the workbook cannot save as that name as it was opened as read only.

This is the code I have:

Code:
SetAttr ActiveWorkbook.Path & "\" & ActiveWorkbook.Name, vbNormal
Application.DisplayAlerts = False
ActiveWorkbook.Save
Application.DisplayAlerts = True

Any ideas?

Many Thanks,
LSM1604
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
You might try

Code:
ActiveWorkbook.ChangeFileAccess xlReadWrite

... but I don't know if it will work.
 
Upvote 0
Thanks for the replies.

I have tried the code you have mentioned instead on the Set Attr, and I not get a different error:

"Cannot access read only document..."

Any ideas?

Thanks,

LSM1604
 
Upvote 0
You have to do both:

Code:
    With ActiveWorkbook
        SetAttr .FullName, vbNormal
        .ChangeFileAccess xlReadWrite
 
        Application.DisplayAlerts = False
        .Save
        Application.DisplayAlerts = True
    End With
 
Upvote 0
Hi shg4421,

Thank you very much :). It worked perfectly. I didn't think to try the both together.

Life Saver!

Thanks again,

LSM1604
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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