+ Reply to Thread
Results 1 to 6 of 6

Sub Fires on Worksheet Close

  1. #1
    Registered User
    Join Date
    01-20-2010
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    7

    Question Sub Fires on Worksheet Close

    I am working on a worksheet in which I have an activex combo box. I have a sub (UpdatePrice) that gets called when the change event fires on the combo box. All works well. My question is when I close the workbook, the sub UpdatePrice fires again.

    Anyone have a reason for this?

    Thanks,
    Lee

    Code (located in VBA - Sheet1):
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by germ; 01-20-2010 at 06:00 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Sub Fires on Worksheet Close

    Hello germ,

    OLE object events are handled by the container object. In this case, the container is the worksheet. The container is also responsible for issuing system messages to the object. When the workbook closes all objects are notified starting at the bottom and working up. The OLE objects are notified first, then the worksheets, etc. on up to the application object, Excel itself. Once the ComboBox closes, the text is cleared. Because the worksheet is still open it process the ComboBox_Change event. The worksheet can not close until the modal dialog box is answered.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    01-20-2010
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Sub Fires on Worksheet Close

    Leith,

    Thanks for the response. I believe I understand what you're telling me. How can I get around the code inside of UpdatePrice from firing when the workbook closes then?

    Thanks,
    Lee

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Sub Fires on Worksheet Close

    Hi germ
    I've had this same issue in the past. Try the code in the attached. It's got something to do with m_blnupdating. I'm not schooled enough in VBA to explain it to you. Perhaps someone viewing your thread can explain it to both of us in plain English
    Hope this helps.
    John
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Registered User
    Join Date
    01-20-2010
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Sub Fires on Worksheet Close

    John,

    That code worked perfectly - Thanks!

    One issue - I added a listbox and tried the same code and it did not work. Does something need to change a bit?
    (I've attached an example)

    Thanks,
    Lee
    Attached Files Attached Files
    Last edited by germ; 01-21-2010 at 12:38 PM. Reason: Added Attachment

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Sub Fires on Worksheet Close

    Hi Lee
    If you change your list box property from Multi Line to Single Line the workbook closes without firing the macro. Why? I'll need to spend some time on that.
    John

+ 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