VBA: Allow modifications on open
Solved
BretonBeurre
Posted messages
12
Status
Member
-
fabien25000 Posted messages 697 Status Member -
fabien25000 Posted messages 697 Status Member -
Hello everyone,
I want to open a password-protected file using a macro in VBA. Moreover, I also activated the prompt asking the user for confirmation if they want to make changes to the file:
"The author wants you to open "FileName" as read-only, unless you need to make changes. Do you want to open it as read-only?"
I wrote the following code to open the file with the password, but I get stuck at the read-only message. How can I indicate in my code that no, I do not want to open the file as read-only, in order to make changes (copy/paste data)?
Code:
I tried using "Application.DisplayAlerts = False" but it didn't work, the file opens but in read-only mode. Any other ideas?
Thank you.
Configuration: Windows / Edge 17.17134
I want to open a password-protected file using a macro in VBA. Moreover, I also activated the prompt asking the user for confirmation if they want to make changes to the file:
"The author wants you to open "FileName" as read-only, unless you need to make changes. Do you want to open it as read-only?"
I wrote the following code to open the file with the password, but I get stuck at the read-only message. How can I indicate in my code that no, I do not want to open the file as read-only, in order to make changes (copy/paste data)?
Code:
Sub openFile()
Workbooks.Open Filename:="MyFile", WriteResPassword:="Password"
End Sub
I tried using "Application.DisplayAlerts = False" but it didn't work, the file opens but in read-only mode. Any other ideas?
Thank you.
Configuration: Windows / Edge 17.17134
2 answers
-
Thank you to fabien25000 for finding the solution, here is the code to use when opening the file:
Set wkb = Workbooks.Open(Filename:=sFileName, UpdateLinks:=False, ReadOnly:=True, WriteResPassword:="Password", IgnoreReadOnlyRecommended:=True)
Thanks again to him! -
Hello,
I don't have time to test, but maybe starting with a msgbox asking if modifications are needed or not, if yes readonly:=true, if not false
--
When you only have a hammer, all problems resemble a nail.-
The thing is, you always need to be able to manually open the file, with the option to open it as Read Only or not.
So I tried to create a message box upon opening, but you can't change a file's attributes when it's open. So I had to write code that, depending on the user's response, closes the file, then reopens it while changing its attribute. Except that when reopening it, it asks me again if I want it Read Only or not… Even with "Application.DisplayAlerts = False".... Too bad ;) -
-
-
By VBA code, I need to be able to modify and save "MonFichier.xlsx". But manually, I need to specify upon opening if I want to be in read-only mode or not. So I didn't quite understand exactly what you wanted to do, but in the end, my code should end by telling it to save the changes. Thanks anyway for the ideas! ;)
-
-