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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,813
Office Version
  1. 2010
Platform
  1. Windows
You might try

Code:
ActiveWorkbook.ChangeFileAccess xlReadWrite

... but I don't know if it will work.
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Rich (BB code):
ActiveWorkbook.ChangeFileAccess  xlReadWrite

 

LSM1604

New Member
Joined
Jan 8, 2010
Messages
49
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
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,813
Office Version
  1. 2010
Platform
  1. Windows
You have to do both:

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

LSM1604

New Member
Joined
Jan 8, 2010
Messages
49
Hi shg4421,

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

Life Saver!

Thanks again,

LSM1604
 

Forum statistics

Threads
1,141,019
Messages
5,703,760
Members
421,315
Latest member
awaisnazir139

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
Top