为Excel输入错误的密码时出现的消息 [英] message when wrong pwd entered for excel
本文介绍了为Excel输入错误的密码时出现的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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
如果输入了错误的密码而没有关闭应用程序,请任何人帮助我显示错误,在此先感谢.
[edit]更改了报价以允许使用语法着色-OriginalGriff [/edit]
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]
推荐答案
您好,
您可以通过以下方式进行操作:
Hi,
you can do it in this way:
Err_UpLd:
If(Err.Number = 91) then
MsgBox "Wrong password"
End If
End Sub
更新:
或者,
Update:
Or,
Err_UpLd:
If(Err.Description <> "") Then
MsgBox "Error Ocurred --> " & Err.Description
End If
希望这就是您想要的.
I hope this is what you wanted.
这篇关于为Excel输入错误的密码时出现的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文