Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password protected, workbook open error

Status
Not open for further replies.

sochidog

Technical User
Jun 26, 2003
22
CA
Hi There,
Im saving an excel workbook using VBA that is password protected... I have turned off every known event and handled all errors, however when someone provides the wrong password to open the workbook, I get "password error". I dont like popups and want to handle it but its not working... thoughts?
K.

ThisWorkbook.SaveCopyAs (GetCurrPath & "\" & NewName & ".xls")

Dim answer As String, i As Integer

Application.EnableEvents = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False

answer = InputBox("Provide Password to Open the Extract - its the same as the source document", "Password to Open the Extract")
Set NewBook = Nothing

On Error Resume Next

Set NewBook = Excel.Workbooks.Open(GetCurrPath & "\" & NewName & ".xls", , , , answer)

If Err <> 0 Then
MsgBox "Incorrect Password"
End If

Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
 
its the same as the source document
So, why not testing answer before trying open ing the doc ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Think on it this way.... I give you an excel document.. and you assign a password to it. Then, using code, you copy the document, and open it (using your password) so that both are side by side. The problem is that is you type in the password wrong - so it throws an error trying to open it. I want to catch the error. I have put in error trapping, and stopped application events, but it still throws the error. How do i stop it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top