down with the debug error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Below is vba code to open a file based on a selection in a drop-down box.
The files that are being opened have passwords to open. So when a value is
selected in the drop-down box, excel goes out and opens the file, and then
asks for the password. This is exactly what I want it to do; however, there
is one small problem. If the incorrect password is entered or if the user
hits cancel, the debug option pops up. As I do not want end user to see
this, can I construct some type of if statement that eliminates the debug
error from popping up? Also, one more important piece of info...there is a
unique open password applied to each file.

Private Sub Labor_Template_Change()

If Labor_Template.Value = "" Then
MsgBox "Please select a Function", vbInformation
End If

If Labor_Template.Value <> "" Then
Workbooks.Open
Filename:="H:\GO\FINANCE\BUDGETS\2006_Plan\Assumptions\Assmptn_LABOR\" &
"AL_" & Labor_Template.Value & ".xls"
End If
End Sub
 
H7^3,
This worked for me: ( It catches both the [Cancel] button and the wrong
password condition)

Sub Macro1()
On Error GoTo FileNotOpened
Workbooks.Open Filename:="C:\testfile.xls"
MsgBox "File Opened"
Exit Sub

FileNotOpened:
MsgBox "No Luck"
End Sub


Alex J
 

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

Back
Top