ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Stop the Debug option from coming up (https://www.excelbanter.com/excel-programming/398771-stop-debug-option-coming-up.html)

sus1e

Stop the Debug option from coming up
 
I have a code which asks the user to input a password before it will continue
with the code. If the password is incorrect it puts up a message box which
informs the user. At this point, I get the microsoft error message which
gives the user the option to debug............ I don't want this to occur.

Is there any way I can stop the microsoft error message from coming up?

My current code looks like:

Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("admin") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required")
If MyStr1 = MyStr2 Then
ActiveSheet.Unprotect Password:=MyStr1
Else
MsgBox ("Access Denied")
End If

Rest of code.....................

Thanks in advance.

Mike H

Stop the Debug option from coming up
 
The code you have posted shouldn't cause the debug option window to pop up so
it must be some other part of the code after the endif so try this small
change:-

Sub Sonic()
Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("admin") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required")
If MyStr1 = MyStr2 Then
ActiveSheet.Unprotect Password:=MyStr1
Else
MsgBox ("Access Denied")
Exit Sub
End If
End Sub


Mike

"sus1e" wrote:

I have a code which asks the user to input a password before it will continue
with the code. If the password is incorrect it puts up a message box which
informs the user. At this point, I get the microsoft error message which
gives the user the option to debug............ I don't want this to occur.

Is there any way I can stop the microsoft error message from coming up?

My current code looks like:

Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("admin") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required")
If MyStr1 = MyStr2 Then
ActiveSheet.Unprotect Password:=MyStr1
Else
MsgBox ("Access Denied")
End If

Rest of code.....................

Thanks in advance.


Stefi

Stop the Debug option from coming up
 
Put an
Exit Sub
or an
Application.Quit
line after MsgBox!

Regards,
Stefi


€žsus1e€ť ezt Ă*rta:

I have a code which asks the user to input a password before it will continue
with the code. If the password is incorrect it puts up a message box which
informs the user. At this point, I get the microsoft error message which
gives the user the option to debug............ I don't want this to occur.

Is there any way I can stop the microsoft error message from coming up?

My current code looks like:

Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("admin") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required")
If MyStr1 = MyStr2 Then
ActiveSheet.Unprotect Password:=MyStr1
Else
MsgBox ("Access Denied")
End If

Rest of code.....................

Thanks in advance.


joel

Stop the Debug option from coming up
 
First there is an error someplace else in the code. That is why the debug
error messagge is showing up. I would recommend finding and fixing this
problem.

You can add On Error

On Error GoTo line

On Error Resume Next

On Error GoTo 0
------------------------------------------------------------------------------
Sub OnErrorStatementDemo()
On Error GoTo ErrorHandler ' Enable error-handling routine.
Open "TESTFILE" For Output As #1 ' Open file for output.
Kill "TESTFILE" ' Attempt to delete open
' file.
On Error Goto 0 ' Turn off error trapping.
On Error Resume Next ' Defer error trapping.
ObjectRef = GetObject("MyWord.Basic") ' Try to start nonexistent
' object, then test for
'Check for likely Automation errors.
If Err.Number = 440 Or Err.Number = 432 Then
' Tell user what happened. Then clear the Err object.
Msg = "There was an error attempting to open the Automation object!"
MsgBox Msg, , "Deferred Error Test"
Err.Clear ' Clear Err object fields
End If
Exit Sub ' Exit to avoid handler.
ErrorHandler: ' Error-handling routine.
Select Case Err.Number ' Evaluate error number.
Case 55 ' "File already open" error.
Close #1 ' Close open file.
Case Else
' Handle other situations here...
End Select
Resume ' Resume execution at same line
' that caused the error.
End Sub




"sus1e" wrote:

I have a code which asks the user to input a password before it will continue
with the code. If the password is incorrect it puts up a message box which
informs the user. At this point, I get the microsoft error message which
gives the user the option to debug............ I don't want this to occur.

Is there any way I can stop the microsoft error message from coming up?

My current code looks like:

Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("admin") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required")
If MyStr1 = MyStr2 Then
ActiveSheet.Unprotect Password:=MyStr1
Else
MsgBox ("Access Denied")
End If

Rest of code.....................

Thanks in advance.


sus1e

Stop the Debug option from coming up
 
That worked wonderfully, thank you.............

All I needed was the Exit sub bit!

"Mike H" wrote:

The code you have posted shouldn't cause the debug option window to pop up so
it must be some other part of the code after the endif so try this small
change:-

Sub Sonic()
Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("admin") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required")
If MyStr1 = MyStr2 Then
ActiveSheet.Unprotect Password:=MyStr1
Else
MsgBox ("Access Denied")
Exit Sub
End If
End Sub


Mike

"sus1e" wrote:

I have a code which asks the user to input a password before it will continue
with the code. If the password is incorrect it puts up a message box which
informs the user. At this point, I get the microsoft error message which
gives the user the option to debug............ I don't want this to occur.

Is there any way I can stop the microsoft error message from coming up?

My current code looks like:

Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("admin") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required")
If MyStr1 = MyStr2 Then
ActiveSheet.Unprotect Password:=MyStr1
Else
MsgBox ("Access Denied")
End If

Rest of code.....................

Thanks in advance.


sus1e

Stop the Debug option from coming up
 
Thank you very much - Its now working fine.

"Stefi" wrote:

Put an
Exit Sub
or an
Application.Quit
line after MsgBox!

Regards,
Stefi


€žsus1e€ť ezt Ă*rta:

I have a code which asks the user to input a password before it will continue
with the code. If the password is incorrect it puts up a message box which
informs the user. At this point, I get the microsoft error message which
gives the user the option to debug............ I don't want this to occur.

Is there any way I can stop the microsoft error message from coming up?

My current code looks like:

Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("admin") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required")
If MyStr1 = MyStr2 Then
ActiveSheet.Unprotect Password:=MyStr1
Else
MsgBox ("Access Denied")
End If

Rest of code.....................

Thanks in advance.


sus1e

Stop the Debug option from coming up
 
Thank you,

The Exit sub as suggested by Mike and Stefi fixed the problem.

"Joel" wrote:

First there is an error someplace else in the code. That is why the debug
error messagge is showing up. I would recommend finding and fixing this
problem.

You can add On Error

On Error GoTo line

On Error Resume Next

On Error GoTo 0
------------------------------------------------------------------------------
Sub OnErrorStatementDemo()
On Error GoTo ErrorHandler ' Enable error-handling routine.
Open "TESTFILE" For Output As #1 ' Open file for output.
Kill "TESTFILE" ' Attempt to delete open
' file.
On Error Goto 0 ' Turn off error trapping.
On Error Resume Next ' Defer error trapping.
ObjectRef = GetObject("MyWord.Basic") ' Try to start nonexistent
' object, then test for
'Check for likely Automation errors.
If Err.Number = 440 Or Err.Number = 432 Then
' Tell user what happened. Then clear the Err object.
Msg = "There was an error attempting to open the Automation object!"
MsgBox Msg, , "Deferred Error Test"
Err.Clear ' Clear Err object fields
End If
Exit Sub ' Exit to avoid handler.
ErrorHandler: ' Error-handling routine.
Select Case Err.Number ' Evaluate error number.
Case 55 ' "File already open" error.
Close #1 ' Close open file.
Case Else
' Handle other situations here...
End Select
Resume ' Resume execution at same line
' that caused the error.
End Sub




"sus1e" wrote:

I have a code which asks the user to input a password before it will continue
with the code. If the password is incorrect it puts up a message box which
informs the user. At this point, I get the microsoft error message which
gives the user the option to debug............ I don't want this to occur.

Is there any way I can stop the microsoft error message from coming up?

My current code looks like:

Dim MyStr1 As String, MyStr2 As String
MyStr2 = ("admin") 'This is the password and it is CASE sensitive
MyStr1 = InputBox("Password Required")
If MyStr1 = MyStr2 Then
ActiveSheet.Unprotect Password:=MyStr1
Else
MsgBox ("Access Denied")
End If

Rest of code.....................

Thanks in advance.



All times are GMT +1. The time now is 01:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com