Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
VB
Private Sub pr_ExcelFileImport()
    Dim m_XlsFl                 As Excel.Application    'Excel.Application
    Dim m_XlsWbk                As Excel.Workbook

    On Error GoTo Err_UpLd

    Screen.MousePointer = vbDefault

    Dim xlFlPasswrd As Variant
    xlFlPasswrd = InputBox("Enter Password for opening of Excel file")

    If xlFlPasswrd = "" Then
    Exit Sub
    End If

    m_XlsFl.Workbooks.Open m_XlsFileNm, Password:=xlFlPasswrd  ' here the error occurs, error no 91 when input wrong password.
 ‘ my codes here……………………
    m_XlsFl.ActiveWorkbook.Close False
    m_XlsFl.Workbooks.Close
    m_XlsFl.Quit
    Set m_XlsFl = Nothing

Err_UpLd:
‘ I wants to do is if err.number = 91 then msgbox "wrong password"
End Sub

Please anyone help me to show error if wrong password entered without closing application, Thanks in advance.

[edit]Quotes changed to allow syntax coloring to work - OriginalGriff[/edit]
Posted
Updated 4-Jul-11 21:15pm
v2
Comments
Sahu.Ashok 5-Jul-11 3:27am    
Thanks OriginalGriff....

1 solution

Hi,
you can do it in this way:

VB
Err_UpLd:
   If(Err.Number = 91) then
      MsgBox "Wrong password"
   End If 
End Sub


Update:
Or,

VB
Err_UpLd:
If(Err.Description <> "") Then
   MsgBox "Error Ocurred --> " & Err.Description
End If


I hope this is what you wanted.
 
Share this answer
 
v3
Comments
Sahu.Ashok 5-Jul-11 4:23am    
Thnks Tarun,
I have allready used this, my problem is that when the error occurs it does not goes to label Err_uplod:. The error shows at the same line
Tarun.K.S 5-Jul-11 5:15am    
That's weird. It works fine here. Let me update the answer with one more thing.
Sahu.Ashok 5-Jul-11 6:15am    
Thanks tarun,
it does not matter that what the error nomber or message, the execution shows error at the same line. It does not go to the label. So plese help me...
Tarun.K.S 5-Jul-11 6:44am    
I'm feeling helpless as I'm not able to figure out why is it not going to the Err_UpLd.
Sahu.Ashok 5-Jul-11 8:49am    
Ohh.. me too, reply me if any solution, Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900