View Full Version : Read Only to Read/Write and back again
Sir Babydum GBE
08-03-2007, 09:54 AM
Hi
Is it possible to open a document in Read-only but allow a macro to make changes to that document and then switch it back to read-only?
Thanks
Bob Phillips
08-03-2007, 10:10 AM
Dim wb As Workbook
Set wb = Workbooks.Open("C:\Test\Read only.xls", ReadOnly:=True)
'do stuff
wb.Worksheets(1).Range("A1").Value = "HaHa"
wb.ChangeFileAccess xlReadWrite
wb.Save
wb.ChangeFileAccess xlReadOnly
'should error here"
wb.Save
Sir Babydum GBE
08-07-2007, 03:29 AM
Dim wb As Workbook
Set wb = Workbooks.Open("C:\Test\Read only.xls", ReadOnly:=True)
'do stuff
wb.Worksheets(1).Range("A1").Value = "HaHa"
wb.ChangeFileAccess xlReadWrite
wb.Save
wb.ChangeFileAccess xlReadOnly
'should error here"
wb.Save
Thanks Mr X,
It didn't actually work because it wouldn't save the workbook once it was read only.
But I learnt the correct codes from you answer and modified it. Basically I create a copy of the workbook, then change the permission in the now closed workbook, do the changes and save it, then reopen it.
Bob Phillips
08-07-2007, 03:45 AM
As I said in the code comments, it would error there. That was to prove it was read only.
Sir Babydum GBE
08-07-2007, 03:48 AM
Sorry Bob,
You're quite right - and no criticism intended - your code still gave me the answer.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.