+ Reply to Thread
Results 1 to 10 of 10

easy vba question

  1. #1
    Pierre via OfficeKB.com
    Guest

    easy vba question

    Hi experts,
    i have a button on a userform called 'cancel'
    the sub looks like

    Private Sub but_cancel_login_Click()
    MsgBox "The program is closed", , "DPA"
    error_h 'sub that saves the workbook in a particular way
    End Sub

    On compiling it gives me an error on the line error_h
    The error states that a variable or procedure is expected and not a module

    I would just like to show the message and then execute the error_h module
    Any ideas?
    ThanksPierre


    --
    Message posted via OfficeKB.com
    http://www.officekb.com/Uwe/Forums.a...mming/200511/1

  2. #2
    damorrison
    Guest

    Re: easy vba question

    try this
    Application.Run "error_h"


  3. #3
    Norman Jones
    Guest

    Re: easy vba question

    Hi Pierre,

    Do you also have a module named error_h?

    If so, rename the module or the sub.


    ---
    Regards,
    Norman



    "Pierre via OfficeKB.com" <u13950@uwe> wrote in message
    news:56e638f52f5ef@uwe...
    > Hi experts,
    > i have a button on a userform called 'cancel'
    > the sub looks like
    >
    > Private Sub but_cancel_login_Click()
    > MsgBox "The program is closed", , "DPA"
    > error_h 'sub that saves the workbook in a particular
    > way
    > End Sub
    >
    > On compiling it gives me an error on the line error_h
    > The error states that a variable or procedure is expected and not a module
    >
    > I would just like to show the message and then execute the error_h module
    > Any ideas?
    > ThanksPierre
    >
    >
    > --
    > Message posted via OfficeKB.com
    > http://www.officekb.com/Uwe/Forums.a...mming/200511/1




  4. #4
    Pierre via OfficeKB.com
    Guest

    Re: easy vba question

    Hi norman,

    yes i have a module called error_h but that is the module i would like to
    execute !
    any suggestions?
    thanks,
    Pierre


    Norman Jones wrote:
    >Hi Pierre,
    >
    >Do you also have a module named error_h?
    >
    >If so, rename the module or the sub.
    >
    >---
    >Regards,
    >Norman
    >
    >> Hi experts,
    >> i have a button on a userform called 'cancel'

    >[quoted text clipped - 12 lines]
    >> Any ideas?
    >> ThanksPierre



    --
    Message posted via OfficeKB.com
    http://www.officekb.com/Uwe/Forums.a...mming/200511/1

  5. #5
    Dave Peterson
    Guest

    Re: easy vba question

    If you have a module and a subroutine/function named the same thing, then excel
    can get confused.

    Change the name of the module to something else:
    Mod_error_h

    Into the VBE
    Show the project explorer (ctrl-r)
    select your module
    hit F4 to see its properties
    Change the value in the (Name) box.



    "Pierre via OfficeKB.com" wrote:
    >
    > Hi norman,
    >
    > yes i have a module called error_h but that is the module i would like to
    > execute !
    > any suggestions?
    > thanks,
    > Pierre
    >
    > Norman Jones wrote:
    > >Hi Pierre,
    > >
    > >Do you also have a module named error_h?
    > >
    > >If so, rename the module or the sub.
    > >
    > >---
    > >Regards,
    > >Norman
    > >
    > >> Hi experts,
    > >> i have a button on a userform called 'cancel'

    > >[quoted text clipped - 12 lines]
    > >> Any ideas?
    > >> ThanksPierre

    >
    > --
    > Message posted via OfficeKB.com
    > http://www.officekb.com/Uwe/Forums.a...mming/200511/1


    --

    Dave Peterson

  6. #6
    Tom Ogilvy
    Guest

    Re: easy vba question

    You can run Sub's or Function's. Modules contain Sub's and Function's

    --
    Regards,
    Tom Ogilvy

    "Pierre via OfficeKB.com" <u13950@uwe> wrote in message
    news:56e96e3066094@uwe...
    > Hi norman,
    >
    > yes i have a module called error_h but that is the module i would like to
    > execute !
    > any suggestions?
    > thanks,
    > Pierre
    >
    >
    > Norman Jones wrote:
    > >Hi Pierre,
    > >
    > >Do you also have a module named error_h?
    > >
    > >If so, rename the module or the sub.
    > >
    > >---
    > >Regards,
    > >Norman
    > >
    > >> Hi experts,
    > >> i have a button on a userform called 'cancel'

    > >[quoted text clipped - 12 lines]
    > >> Any ideas?
    > >> ThanksPierre

    >
    >
    > --
    > Message posted via OfficeKB.com
    > http://www.officekb.com/Uwe/Forums.a...mming/200511/1




  7. #7
    Pierre via OfficeKB.com
    Guest

    Re: easy vba question

    Thanks for the help, i didn't see this in my code !
    it works now !
    Pierre


    Dave Peterson wrote:
    >If you have a module and a subroutine/function named the same thing, then excel
    >can get confused.
    >
    >Change the name of the module to something else:
    >Mod_error_h
    >
    >Into the VBE
    >Show the project explorer (ctrl-r)
    >select your module
    >hit F4 to see its properties
    >Change the value in the (Name) box.
    >
    >> Hi norman,
    >>

    >[quoted text clipped - 19 lines]
    >> >> Any ideas?
    >> >> ThanksPierre

    >



    --
    Message posted via OfficeKB.com
    http://www.officekb.com/Uwe/Forums.a...mming/200511/1

  8. #8
    Pierre via OfficeKB.com
    Guest

    Re: easy vba question

    Thanks Tom, I know now !
    Pierre

    Tom Ogilvy wrote:
    >You can run Sub's or Function's. Modules contain Sub's and Function's
    >
    >> Hi norman,
    >>

    >[quoted text clipped - 19 lines]
    >> >> Any ideas?
    >> >> ThanksPierre



    --
    Message posted via OfficeKB.com
    http://www.officekb.com/Uwe/Forums.a...mming/200511/1

  9. #9
    Pierre via OfficeKB.com
    Guest

    Re: easy vba question

    Hi tom,

    i now have:

    - a workbook open sub in which the first line should be : on error goto
    error_h

    error_h() is in the module error_handling

    ho can i get the on error goto routine to start error_h in module
    error_handling ?

    When i try my code i get the message:
    "name not defined"

    Thanks,
    Pierre

    Tom Ogilvy wrote:
    >You can run Sub's or Function's. Modules contain Sub's and Function's
    >
    >> Hi norman,
    >>

    >[quoted text clipped - 19 lines]
    >> >> Any ideas?
    >> >> ThanksPierre



    --
    Message posted via http://www.officekb.com

  10. #10
    Dave Peterson
    Guest

    Re: easy vba question

    Take a look at VBA's help for "On Error". You'll see this:

    Enables an error-handling routine and specifies the location of the routine
    within a procedure...

    So you're off to some place within that same procedure.


    Maybe you could use:

    Option Explicit
    Sub yoursub()

    On Error GoTo ThisProcedureErrorHandling:

    'your code here

    Exit Sub 'avoid the error handler


    ThisProcedureErrorHandling:
    Call error_h
    'or
    'Call error_handling.error_h
    Resume Next '???
    End Sub

    and in the error_handling module:

    Option Explicit
    Sub error_h()
    MsgBox Err.Number
    Err.Clear
    End Sub



    "Pierre via OfficeKB.com" wrote:
    >
    > Hi tom,
    >
    > i now have:
    >
    > - a workbook open sub in which the first line should be : on error goto
    > error_h
    >
    > error_h() is in the module error_handling
    >
    > ho can i get the on error goto routine to start error_h in module
    > error_handling ?
    >
    > When i try my code i get the message:
    > "name not defined"
    >
    > Thanks,
    > Pierre
    >
    > Tom Ogilvy wrote:
    > >You can run Sub's or Function's. Modules contain Sub's and Function's
    > >
    > >> Hi norman,
    > >>

    > >[quoted text clipped - 19 lines]
    > >> >> Any ideas?
    > >> >> ThanksPierre

    >
    > --
    > Message posted via http://www.officekb.com


    --

    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