Folks,
I am designing a workbook (a 'policy attestation tool') to use when launching new policies, and require (circa 800) staff to attest that they have read the launched policy. In short, the when the staff member clicks on the "attest" button, the tool will open a password-protected attestation register (on a shared drive) and update the relevant individual's record, before saving and closing the register. Where this process fails (e.g. new staff members may not yet have been given access to shared directory, or if somebody else already has the register open), then the tool will revert to an exceptions routine and generate an email to Compliance (who can then update the register accordingly).
This all works well, except that if somebody else already has the register open, then at the workbook.open step in the code, the user gets a prompt that the workbook is protected and prompts for a password (after which the register opens in readonly). Now the code should have already provided the password (and that works fine in normal situations, when the register isn't already open) - I need to get rid of that prompt and have the code revert to the exceptions process (ManualExceptionsProcess), but am struggling to find a way to do this...
Relevant (simplified) code below:
I need this to work without any alerts / needs to manually enter a password. Does anyone have any thoughts how to resolve this?
Thanks
Bcfaigg
I am designing a workbook (a 'policy attestation tool') to use when launching new policies, and require (circa 800) staff to attest that they have read the launched policy. In short, the when the staff member clicks on the "attest" button, the tool will open a password-protected attestation register (on a shared drive) and update the relevant individual's record, before saving and closing the register. Where this process fails (e.g. new staff members may not yet have been given access to shared directory, or if somebody else already has the register open), then the tool will revert to an exceptions routine and generate an email to Compliance (who can then update the register accordingly).
This all works well, except that if somebody else already has the register open, then at the workbook.open step in the code, the user gets a prompt that the workbook is protected and prompts for a password (after which the register opens in readonly). Now the code should have already provided the password (and that works fine in normal situations, when the register isn't already open) - I need to get rid of that prompt and have the code revert to the exceptions process (ManualExceptionsProcess), but am struggling to find a way to do this...
Relevant (simplified) code below:
VBA Code:
Sub Attestation()
On Error GoTo ManualExceptionsProcess
Application.DisplayAlerts = False
Workbooks.Open Filename:= _
"\\wwp\data\Investment Data\WICN\Compliance\Compliance Admin\EMEA-Investments-Policy-Attestation-Register.xlsx", Password:="password"
If Workbooks("EMEA-Investments-Policy-Attestation-Register.xlsx").ReadOnly Then 'if somebody is already in register and so opens in read-only - goto manual process
Workbooks("EMEA-Investments-Policy-Attestation-Register.xlsx").Close savechanges:=False
GoTo ManualExceptionsProcess
End If
On Error Resume Next
Application.DisplayAlerts = True
SearchEntries 'update register
Workbooks("EMEA-Investments-Policy-Attestation-Register.xlsx").Close savechanges:=True
Application.ScreenUpdating = True
Workbooks("Policy-Attestation-Tool.xlsm").Close savechanges:=False
End
ManualExceptionsProcess:
Application.DisplayAlerts = True
Sheets("Attestation").Unprotect Password:="password"
x = MsgBox("I was unable to update the Policy Attestation Register." & Chr(10) & Chr(10) & "I will generate an email for you to send to Compliance, confirming you have read the required documents.", vbExclamation)
SendManualAttestationEmail
Application.ScreenUpdating = True
Application.DisplayAlerts = True
ActiveWorkbook.Close savechanges:=False
End Sub
I need this to work without any alerts / needs to manually enter a password. Does anyone have any thoughts how to resolve this?
Thanks
Bcfaigg