View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Alex J Alex J is offline
external usenet poster
 
Posts: 85
Default down with the debug error

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

"hurlbut777" wrote in message
...
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\Assumpt ions\Assmptn_LABOR\" &
"AL_" & Labor_Template.Value & ".xls"
End If
End Sub