+ Reply to Thread
Results 1 to 10 of 10

ingnore nonexisting subrouitine

Hybrid View

  1. #1
    Jack Sons
    Guest

    ingnore nonexisting subrouitine

    Hi all,

    In the code below ABCD can be executed if it is a subroutine - sub ABCD() -
    in a module elsewhere in the same project. If ABCD is a not an existing sub
    the execution will halt, an error message wil appear on screen and a sound
    wil be produced. Fore some reason I want to hear that sound but I don't want
    the the program to halt. If possible it would be nice if also the message
    box does not appear, but I need to hear the error sound. To my regret I did
    not succeed with the code below.

    Anybody who knows what code is needed to let the program continue when
    execution comes to the line with the undefined ABCD but do let the error
    message sound hear?

    Jack Sons
    The Netherlands


    Sub ingnoreABCD()
    ............ ' here the program already did some things
    Application.DisplayAlerts = False
    ABCD
    Application.DisplayAlerts = True
    ............... ' here I want to do what the program should do
    End Sub



  2. #2
    Ron de Bruin
    Guest

    Re: ingnore nonexisting subrouitine

    Hi Jack

    See this code on Chip's site

    You can use the VBA Extensibility tools to determine whether a module exists, or a procedure exists in a module.

    Function ModuleExists(ModuleName As String) As Boolean
    On Error Resume Next
    ModuleExists = Len( _
    ThisWorkbook.VBProject.VBComponents(ModuleName).Name) <> 0
    End Function

    Function ProcedureExists(ProcedureName As String, _
    ModuleName As String) As Boolean
    On Error Resume Next
    If ModuleExists(ModuleName) = True Then
    ProcedureExists = ThisWorkbook.VBProject.VBComponents(ModuleName) _
    .CodeModule.ProcStartLine(ProcedureName, vbext_pk_Proc) <> 0
    End If
    End Function

    http://www.cpearson.com/excel/vbe.htm




    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "Jack Sons" <j.sons@planet.nl> wrote in message news:%23LY9Q4qtFHA.736@TK2MSFTNGP10.phx.gbl...
    > Hi all,
    >
    > In the code below ABCD can be executed if it is a subroutine - sub ABCD() - in a module elsewhere in the same project. If ABCD is
    > a not an existing sub the execution will halt, an error message wil appear on screen and a sound wil be produced. Fore some reason
    > I want to hear that sound but I don't want the the program to halt. If possible it would be nice if also the message box does not
    > appear, but I need to hear the error sound. To my regret I did not succeed with the code below.
    >
    > Anybody who knows what code is needed to let the program continue when execution comes to the line with the undefined ABCD but do
    > let the error message sound hear?
    >
    > Jack Sons
    > The Netherlands
    >
    >
    > Sub ingnoreABCD()
    > ........... ' here the program already did some things
    > Application.DisplayAlerts = False
    > ABCD
    > Application.DisplayAlerts = True
    > .............. ' here I want to do what the program should do
    > End Sub
    >




  3. #3
    Ron Rosenfeld
    Guest

    Re: ingnore nonexisting subrouitine

    On Sun, 11 Sep 2005 10:51:55 +0200, "Jack Sons" <j.sons@planet.nl> wrote:

    >Hi all,
    >
    >In the code below ABCD can be executed if it is a subroutine - sub ABCD() -
    >in a module elsewhere in the same project. If ABCD is a not an existing sub
    >the execution will halt, an error message wil appear on screen and a sound
    >wil be produced. Fore some reason I want to hear that sound but I don't want
    >the the program to halt. If possible it would be nice if also the message
    >box does not appear, but I need to hear the error sound. To my regret I did
    >not succeed with the code below.
    >
    >Anybody who knows what code is needed to let the program continue when
    >execution comes to the line with the undefined ABCD but do let the error
    >message sound hear?
    >
    >Jack Sons
    >The Netherlands
    >
    >
    >Sub ingnoreABCD()
    >........... ' here the program already did some things
    >Application.DisplayAlerts = False
    >ABCD
    >Application.DisplayAlerts = True
    >.............. ' here I want to do what the program should do
    >End Sub
    >


    Take a look at the On Error statement and also the Beep statement.


    --ron

  4. #4
    Norman Jones
    Guest

    Re: ingnore nonexisting subrouitine

    Hi Ron.

    > Take a look at the On Error statement and also the Beep statement.


    I do not think that a call to a non-existant procedure produces a trappable
    error.

    I think that the approach similar to that advocated by Ron de Bruin would be
    necessary.

    ---
    Regards,
    Norman


    "Ron Rosenfeld" <ronrosenfeld@nospam.org> wrote in message
    news:7338i1denvtumiej4ioctebskgmtqerebg@4ax.com...
    > On Sun, 11 Sep 2005 10:51:55 +0200, "Jack Sons" <j.sons@planet.nl> wrote:
    >
    >>Hi all,
    >>
    >>In the code below ABCD can be executed if it is a subroutine - sub
    >>ABCD() -
    >>in a module elsewhere in the same project. If ABCD is a not an existing
    >>sub
    >>the execution will halt, an error message wil appear on screen and a sound
    >>wil be produced. Fore some reason I want to hear that sound but I don't
    >>want
    >>the the program to halt. If possible it would be nice if also the message
    >>box does not appear, but I need to hear the error sound. To my regret I
    >>did
    >>not succeed with the code below.
    >>
    >>Anybody who knows what code is needed to let the program continue when
    >>execution comes to the line with the undefined ABCD but do let the error
    >>message sound hear?
    >>
    >>Jack Sons
    >>The Netherlands
    >>
    >>
    >>Sub ingnoreABCD()
    >>........... ' here the program already did some things
    >>Application.DisplayAlerts = False
    >>ABCD
    >>Application.DisplayAlerts = True
    >>.............. ' here I want to do what the program should do
    >>End Sub
    >>

    >
    > Take a look at the On Error statement and also the Beep statement.
    >
    >
    > --ron




  5. #5
    Ron Rosenfeld
    Guest

    Re: ingnore nonexisting subrouitine

    On Sun, 11 Sep 2005 12:07:48 +0100, "Norman Jones"
    <normanjones@whereforartthou.com> wrote:

    >Hi Ron.
    >
    >> Take a look at the On Error statement and also the Beep statement.

    >
    >I do not think that a call to a non-existant procedure produces a trappable
    >error.
    >
    >I think that the approach similar to that advocated by Ron de Bruin would be
    >necessary.
    >
    >---
    >Regards,
    >Norman


    I didn't realize that. Thank you for pointing it out.
    --ron

  6. #6
    Jack Sons
    Guest

    Re: ingnore nonexisting subrouitine

    Ron,

    I already tried On Error resume next like low, but it didn't help. Other
    ideas?

    Jack.


    Sub ingnoreABCD()
    ............ ' here the program already did some things
    Application.DisplayAlerts = False
    On Error Resume Next
    ABCD
    Application.DisplayAlerts = True
    ............... ' here I want to do what the program should do
    End Sub




    "Ron Rosenfeld" <ronrosenfeld@nospam.org> schreef in bericht
    news:7338i1denvtumiej4ioctebskgmtqerebg@4ax.com...
    > On Sun, 11 Sep 2005 10:51:55 +0200, "Jack Sons" <j.sons@planet.nl> wrote:
    >
    >>Hi all,
    >>
    >>In the code below ABCD can be executed if it is a subroutine - sub
    >>ABCD() -
    >>in a module elsewhere in the same project. If ABCD is a not an existing
    >>sub
    >>the execution will halt, an error message wil appear on screen and a sound
    >>wil be produced. Fore some reason I want to hear that sound but I don't
    >>want
    >>the the program to halt. If possible it would be nice if also the message
    >>box does not appear, but I need to hear the error sound. To my regret I
    >>did
    >>not succeed with the code below.
    >>
    >>Anybody who knows what code is needed to let the program continue when
    >>execution comes to the line with the undefined ABCD but do let the error
    >>message sound hear?
    >>
    >>Jack Sons
    >>The Netherlands
    >>
    >>
    >>Sub ingnoreABCD()
    >>........... ' here the program already did some things
    >>Application.DisplayAlerts = False
    >>ABCD
    >>Application.DisplayAlerts = True
    >>.............. ' here I want to do what the program should do
    >>End Sub
    >>

    >
    > Take a look at the On Error statement and also the Beep statement.
    >
    >
    > --ron




  7. #7
    Ron Rosenfeld
    Guest

    Re: ingnore nonexisting subrouitine

    On Sun, 11 Sep 2005 13:37:45 +0200, "Jack Sons" <j.sons@planet.nl> wrote:

    >Ron,
    >
    >I already tried On Error resume next like low, but it didn't help. Other
    >ideas?
    >
    >Jack.



    See Ron de Bruin's suggestion
    --ron

  8. #8
    Dave Peterson
    Guest

    Re: ingnore nonexisting subrouitine

    I think Ron forgot to add to change the Call to Application.Run <bg>.

    This "worked" for me if I spelled "doesitexist" as "NoItDoesNot".

    Option Explicit
    Sub aaaa()
    On Error Resume Next
    Application.Run ThisWorkbook.Name & "!doesitexist"
    If Err.Number <> 0 Then
    Beep
    Err.Clear
    End If
    On Error GoTo 0
    End Sub
    Sub doesitexist()
    MsgBox "yes"
    End Sub



    Ron Rosenfeld wrote:
    >
    > On Sun, 11 Sep 2005 10:51:55 +0200, "Jack Sons" <j.sons@planet.nl> wrote:
    >
    > >Hi all,
    > >
    > >In the code below ABCD can be executed if it is a subroutine - sub ABCD() -
    > >in a module elsewhere in the same project. If ABCD is a not an existing sub
    > >the execution will halt, an error message wil appear on screen and a sound
    > >wil be produced. Fore some reason I want to hear that sound but I don't want
    > >the the program to halt. If possible it would be nice if also the message
    > >box does not appear, but I need to hear the error sound. To my regret I did
    > >not succeed with the code below.
    > >
    > >Anybody who knows what code is needed to let the program continue when
    > >execution comes to the line with the undefined ABCD but do let the error
    > >message sound hear?
    > >
    > >Jack Sons
    > >The Netherlands
    > >
    > >
    > >Sub ingnoreABCD()
    > >........... ' here the program already did some things
    > >Application.DisplayAlerts = False
    > >ABCD
    > >Application.DisplayAlerts = True
    > >.............. ' here I want to do what the program should do
    > >End Sub
    > >

    >
    > Take a look at the On Error statement and also the Beep statement.
    >
    > --ron


    --

    Dave Peterson

  9. #9
    Norman Jones
    Guest

    Re: ingnore nonexisting subrouitine

    Hi Dave,

    A good idea!

    I had not thought of using the procedure's name string (as required by the
    Run method) and thus avoiding the compile error.

    Thank you!

    ---
    Regards,
    Norman



    "Dave Peterson" <petersod@verizonXSPAM.net> wrote in message
    news:43242957.1418A9ED@verizonXSPAM.net...
    >I think Ron forgot to add to change the Call to Application.Run <bg>.
    >
    > This "worked" for me if I spelled "doesitexist" as "NoItDoesNot".
    >
    > Option Explicit
    > Sub aaaa()
    > On Error Resume Next
    > Application.Run ThisWorkbook.Name & "!doesitexist"
    > If Err.Number <> 0 Then
    > Beep
    > Err.Clear
    > End If
    > On Error GoTo 0
    > End Sub
    > Sub doesitexist()
    > MsgBox "yes"
    > End Sub
    >
    >
    >
    > Ron Rosenfeld wrote:
    >>
    >> On Sun, 11 Sep 2005 10:51:55 +0200, "Jack Sons" <j.sons@planet.nl> wrote:
    >>
    >> >Hi all,
    >> >
    >> >In the code below ABCD can be executed if it is a subroutine - sub
    >> >ABCD() -
    >> >in a module elsewhere in the same project. If ABCD is a not an existing
    >> >sub
    >> >the execution will halt, an error message wil appear on screen and a
    >> >sound
    >> >wil be produced. Fore some reason I want to hear that sound but I don't
    >> >want
    >> >the the program to halt. If possible it would be nice if also the
    >> >message
    >> >box does not appear, but I need to hear the error sound. To my regret I
    >> >did
    >> >not succeed with the code below.
    >> >
    >> >Anybody who knows what code is needed to let the program continue when
    >> >execution comes to the line with the undefined ABCD but do let the error
    >> >message sound hear?
    >> >
    >> >Jack Sons
    >> >The Netherlands
    >> >
    >> >
    >> >Sub ingnoreABCD()
    >> >........... ' here the program already did some things
    >> >Application.DisplayAlerts = False
    >> >ABCD
    >> >Application.DisplayAlerts = True
    >> >.............. ' here I want to do what the program should do
    >> >End Sub
    >> >

    >>
    >> Take a look at the On Error statement and also the Beep statement.
    >>
    >> --ron

    >
    > --
    >
    > Dave Peterson




  10. #10
    Jack Sons
    Guest

    Re: ingnore nonexisting subrouitine

    Dave,

    Thanks for the code.

    Norman,

    Thanks for the explanation.

    Jack.
    "Norman Jones" <normanjones@whereforartthou.com> schreef in bericht
    news:enKoWbttFHA.3896@TK2MSFTNGP15.phx.gbl...
    > Hi Dave,
    >
    > A good idea!
    >
    > I had not thought of using the procedure's name string (as required by the
    > Run method) and thus avoiding the compile error.
    >
    > Thank you!
    >
    > ---
    > Regards,
    > Norman
    >
    >
    >
    > "Dave Peterson" <petersod@verizonXSPAM.net> wrote in message
    > news:43242957.1418A9ED@verizonXSPAM.net...
    >>I think Ron forgot to add to change the Call to Application.Run <bg>.
    >>
    >> This "worked" for me if I spelled "doesitexist" as "NoItDoesNot".
    >>
    >> Option Explicit
    >> Sub aaaa()
    >> On Error Resume Next
    >> Application.Run ThisWorkbook.Name & "!doesitexist"
    >> If Err.Number <> 0 Then
    >> Beep
    >> Err.Clear
    >> End If
    >> On Error GoTo 0
    >> End Sub
    >> Sub doesitexist()
    >> MsgBox "yes"
    >> End Sub
    >>
    >>
    >>
    >> Ron Rosenfeld wrote:
    >>>
    >>> On Sun, 11 Sep 2005 10:51:55 +0200, "Jack Sons" <j.sons@planet.nl>
    >>> wrote:
    >>>
    >>> >Hi all,
    >>> >
    >>> >In the code below ABCD can be executed if it is a subroutine - sub
    >>> >ABCD() -
    >>> >in a module elsewhere in the same project. If ABCD is a not an existing
    >>> >sub
    >>> >the execution will halt, an error message wil appear on screen and a
    >>> >sound
    >>> >wil be produced. Fore some reason I want to hear that sound but I don't
    >>> >want
    >>> >the the program to halt. If possible it would be nice if also the
    >>> >message
    >>> >box does not appear, but I need to hear the error sound. To my regret I
    >>> >did
    >>> >not succeed with the code below.
    >>> >
    >>> >Anybody who knows what code is needed to let the program continue when
    >>> >execution comes to the line with the undefined ABCD but do let the
    >>> >error
    >>> >message sound hear?
    >>> >
    >>> >Jack Sons
    >>> >The Netherlands
    >>> >
    >>> >
    >>> >Sub ingnoreABCD()
    >>> >........... ' here the program already did some things
    >>> >Application.DisplayAlerts = False
    >>> >ABCD
    >>> >Application.DisplayAlerts = True
    >>> >.............. ' here I want to do what the program should do
    >>> >End Sub
    >>> >
    >>>
    >>> Take a look at the On Error statement and also the Beep statement.
    >>>
    >>> --ron

    >>
    >> --
    >>
    >> Dave Peterson

    >
    >




+ 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