Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Opening a workbook, passwords and error 1004.


Looked through this forum but am not able to find anything related. I
hope that some of you are able to help me.

I'm trying to trap a password error when opening a protected workbook
to give the user another chance to enter it. The problem is though
that when a incorrect password is used I get the general error code
1004 which is basically used for a lot of things and not specific a
password error. Same error I also get when trying to e.g. open a file
other then a workbook.

When I switch error checking on I get the 1004 error plus a description
telling me that the password is incorrect. When error checking is left
off I only get 1004 for the Err parameter. When checking
Err.Description I find it to be a null string, same for
Err.HelpContext.

It's probably a dumm question with an obvious answer but do any of you
know how to trap an incorrect password used when opening a workbook?

Thanks and best regards,

Leon


--
droopy928gt
------------------------------------------------------------------------
droopy928gt's Profile: http://www.excelforum.com/member.php...o&userid=30232
View this thread: http://www.excelforum.com/showthread...hreadid=536709

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Opening a workbook, passwords and error 1004.

This is one way to trap a bad password, fwiw:

Sub OpenWorkbook()
Dim TryCount As Integer
On Error Resume Next
TryAgain:
Err.Clear
Workbooks.Open "C:\withpass.xls"
If InStr(1, Err.Description, "password") 0 Then
If TryCount = 0 Then
MsgBox "Wrong password. Try again"
TryCount = 1
GoTo TryAgain
Else
MsgBox "Sorry"
End If
End If
End Sub


--
Jim
"droopy928gt"
wrote in message
...
|
| Looked through this forum but am not able to find anything related. I
| hope that some of you are able to help me.
|
| I'm trying to trap a password error when opening a protected workbook
| to give the user another chance to enter it. The problem is though
| that when a incorrect password is used I get the general error code
| 1004 which is basically used for a lot of things and not specific a
| password error. Same error I also get when trying to e.g. open a file
| other then a workbook.
|
| When I switch error checking on I get the 1004 error plus a description
| telling me that the password is incorrect. When error checking is left
| off I only get 1004 for the Err parameter. When checking
| Err.Description I find it to be a null string, same for
| Err.HelpContext.
|
| It's probably a dumm question with an obvious answer but do any of you
| know how to trap an incorrect password used when opening a workbook?
|
| Thanks and best regards,
|
| Leon
|
|
| --
| droopy928gt
| ------------------------------------------------------------------------
| droopy928gt's Profile:
http://www.excelforum.com/member.php...o&userid=30232
| View this thread: http://www.excelforum.com/showthread...hreadid=536709
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Opening a workbook, passwords and error 1004.


Hi Jim,

Thanks for your reply. I did previously try both the Err.Description
and Err.HelpContext way but I found both to be a null strings.

HOWEVER, using your code it indeed worked. I still don't understand
why it didn't work for me before though but for the moment that ain't
important.

Thanks again.

Best regards,

Leon


--
droopy928gt
------------------------------------------------------------------------
droopy928gt's Profile: http://www.excelforum.com/member.php...o&userid=30232
View this thread: http://www.excelforum.com/showthread...hreadid=536709

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro runtime 1004 error on opening worksheet Shaggyjh Excel Discussion (Misc queries) 5 May 6th 09 12:37 PM
workbook.open throws 1004 error [email protected] Excel Programming 3 April 3rd 06 11:37 PM
error 1004 Method SaveAs of Workbook failed Maury Markowitz Excel Programming 2 October 25th 05 08:45 PM
shared workbook runtime error 1004 Nigel[_10_] Excel Programming 10 August 2nd 05 07:09 PM
runtime error 1004 when opening excel file via VBA in a browser Ken Hunter Excel Programming 2 July 31st 03 03:33 PM


All times are GMT +1. The time now is 04:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"