Check Excel password VBA

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Check Excel password VBA

Post by agibsonsw »

Hello. Excel 2003.

If my code opens a workbook leaving the user to supply the necessary password, if they get it wrong a VBA End/Debug dialog appears. How can I handle this 'gracefully'. Do I need error handling code or can I get Excel to ask again?

Thanks, Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: Check Excel password VBA

Post by Don Wells »

agibsonsw wrote:Hello. Excel 2003.

If my code opens a workbook leaving the user to supply the necessary password, if they get it wrong a VBA End/Debug dialog appears. How can I handle this 'gracefully'. Do I need error handling code or can I get Excel to ask again?
I would be inclined to use code similar to the following:

Code: Select all

Dim ctr As Long
Pwd_Reqd:
    If ctr = 3 Then GoTo ExitHandler
    On Error Resume Next
    Workbooks.Open Filename:= _
        "C:\Documents and Settings\Wells\My Documents\Trash.xls"
    If Err Then
      ctr = ctr + 1
      On Error GoTo 0
      GoTo Pwd_Reqd
    End If
HTH
Regards
Don

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Check Excel password VBA

Post by agibsonsw »

Hi and thanks for this. IDHTY.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: Check Excel password VBA

Post by Don Wells »

agibsonsw wrote:Hi and thanks for this. IDHTY.
    IDHTY; Huh???
Regards
Don

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Check Excel password VBA

Post by agibsonsw »

'It Did Help, Thank You' - I thought everyone new that ? :grin:
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
HansV
Administrator
Posts: 78549
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Check Excel password VBA

Post by HansV »

No, I didn't "now" it... :smile:
Best wishes,
Hans