i have an issue where the combination of password protection and read only interferes. I have a "data collector" where a lot of people fill in another form and transfer the data via a button. I wanna check if this file everyone writes in is read only (preventing data from not getting lost) and if so you get a message that a transfer is currently in progress and if he/she want's to wait a bit or cancel the process... I realised that as long as the Data Collector is password protected, the macro stops as soon as the file IS read only even though i provided the password.
Sub Readonlytest()
Dim OpenAgain As Integer
DoAgain:
Application.DisplayAlerts = False
Workbooks.Open Filename:= _
"Path\ReadOnly Test.xlsx", Password:="PW"
If Workbooks("ReadOnly Test.xlsx").ReadOnly Then
Workbooks("ReadOnly Test.xlsx").Close (False)
Application.DisplayAlerts = True
OpenAgain = MsgBox("Data Transfer in progress. Try again?", vbYesNo)
If OpenAgain = vbYes Then
Application.Wait (Now + TimeValue("00:00:04"))
GoTo DoAgain
End If
If OpenAgain = vbNo Then
MsgBox "Try again later."
Exit Sub
End If
End If
Any ideas?
- Setting Display Alerts to false didn't work
- when not opened by anyone everything works fine
- if workbook isn't password protected this code works as well
Check if this works: