Forum Discussion
Excel disable Read-Only from SharePoint with VBA
Hello Group,
We have a lot of Excel files that are saved with "read-Only recommended".
I would like to open files with VBA and also capture the click on "Edit Anyway" in code.
I have this code:
Dim exApp As Excel.Application
Dim wb As Excel.Workbook
Set exApp = Excel.Application
DoEvents
exApp.Visible = True
' Set wb = App.Workbooks.Open(Filename:=sfilename, UpdateLinks:=False, ReadOnly:=False, IgnoreReadOnlyRecommended:=true)
Set wb = exApp.Workbooks.Open(Filename:=sfilename, ReadOnly:=False)
DoEvents
If ActiveWorkbook.AutoSaveOn = True Then ActiveWorkbook.AutoSaveOn = False
DoEvents
When I open the file from SharePoint, there is no Read-Only active:
When I open it with the VBA code, Read-Only is activated,
although I have ReadOnly:=False in my Workbooks.Open statement.
How can I make this behave the way I want (so the file is opened in Excel without Read-Only restriction, same as when "Edit Anyway" would have been clicked).
Grtz, Bart
- NikolinoDEGold Contributor
- BartH_NLCopper Contributor
NikolinoDE
Thank you Nikolino, but the problem doesn't exist when I open the file (manually) from SharePoint, but when I open it with VBA.
- Fuzz_ZACopper Contributor
BartH_NL I’ve been bashing my head against this issue for 2 days and thought I’d share a solution that worked for me.
After invoking the Excel.Application and workbook to open (with the ReadOnly parameter set to False), execute the following method:exApp.ActiveWorkbook.LockServerFile()
You will immediately see your visible Excel remove the read only banner and you can merrily save. This method changes the ReadOnly flag from True to False.
Hope this helps.