ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Can i turn off the debug side of Excel? (https://www.excelbanter.com/excel-discussion-misc-queries/26604-can-i-turn-off-debug-side-excel.html)

H the Layman

Can i turn off the debug side of Excel?
 
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,

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")

H the Layman wrote:

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,


--

Dave Peterson


All times are GMT +1. The time now is 10:05 PM.

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