Results 1 to 4 of 4

Thread: [RESOLVED] getting a private sub to run on startup

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2012
    Posts
    90

    Resolved [RESOLVED] getting a private sub to run on startup

    Hi

    I have a private sub routine called 'initProductForm' and this does everything I want when called from a click event; initialises listboxes, populates listboxes, sets screen messages to blank, etc.

    I want the routine to run when the workbook opens and rather than duplicate the code I would like to call the routine when the workbook opens.

    How best to go about achieving this?

    Thanks

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: getting a private sub to run on startup

    put
    initProductForm.show
    in the workbook open event
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2012
    Posts
    90

    Re: getting a private sub to run on startup

    Isn't that for calling a form?

    Sorry, I should have been clearer in my original post.

    I have a sub routine in 'sheet1' called 'InitProduct' and this is a few lines of code that populates a listbox. I want the same code to run whenever the workbook opens but I don't want to copy / paste the same code to different modules.

    So in 'Thisworkbook' module I have a call to 'InitProduct' but the procedure is not found.

    Is there a way from the 'Thisworkbook' module to call sheet1 module called 'InitProduct'?

    Thanks

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: getting a private sub to run on startup

    prefix with sheet

    vb Code:
    1. sheet1.InitProduct
    make sure sub procdure is not private
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width