Can i turn off the debug side of Excel?

G

Guest

I am opening a password protected Excel file from a button assigned with a
macro. However, when i press the button all works fine, the password box
appears for the file. if i enter the pass the file opens fine. The problem
occurs if i cancel the password request. The "debug" box appears and then
goes into editor mode. I do not want this to happen as it presents users with
an opportunity to hack away at the code!!!! Can I stop this from happening?
if so, could somebody please explain how to go about it, in laymans terms....
:) thanks in advance,
 
D

Dave Peterson

You can protect your code within the VBE via:
tools|vbaproject properties|protection tab

Then when your code blows up, the users won't get the debug option.

But better would be to catch the password error and code around it:

Option Explicit
Sub testme()

Dim okToContinue As Boolean
Dim wkbkName As String
Dim wkbk As Workbook

wkbkName = "C:\my documents\excel\book1.xls"

Set wkbk = Nothing
On Error Resume Next
Set wkbk = Workbooks.Open(Filename:=wkbkName)
On Error GoTo 0

If wkbk Is Nothing Then
MsgBox "You didn't open the workbook!"
Exit Sub 'or whatever you want
End If

MsgBox wkbk.FullName

End Sub

====
Is there a reason you don't want your macro to supply the password to the second
workbook?

You could add it on the .open line:

Set wkbk = Workbooks.Open(Filename:=wkbkName, Password:="a")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top