+ Reply to Thread
Results 1 to 2 of 2

down with the debug error

  1. #1
    hurlbut777
    Guest

    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\Assumptions\Assmptn_LABOR\" &
    "AL_" & Labor_Template.Value & ".xls"
    End If
    End Sub

  2. #2
    Alex J
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1