ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   down with the debug error (https://www.excelbanter.com/excel-programming/320326-down-debug-error.html)

hurlbut777

down with the debug error
 
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

Alex J

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





All times are GMT +1. The time now is 02:08 PM.

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