+ Reply to Thread
Results 1 to 4 of 4

workbook close trigger unloading and termination of user forms.

  1. #1
    Registered User
    Join Date
    06-10-2021
    Location
    Sdyney, Australia
    MS-Off Ver
    Excel 365, Excel 2010
    Posts
    10

    workbook close trigger unloading and termination of user forms.

    hi I have a excel VBA Macro program which works fine in Excel 2010 or older version, but it has a problem in excel 365. in the following code, "savefile.close" works fine in excel 2010 by closing a file namely"savefile" , but in excel 365, it would close the file, and also unload all the user forms and trigger the "UserForm_Terminate()". all the user forms are not stored in this "savefile". Unloading user forms would erase and zero all the data in the textboxes of user forms of which I want to keep the values unchanged.

    I tried to run in excel 2010 several times today, and pretty sure this "close" command only close the workbook (savefile) and did not trigger unloading or termination of the user forms.

    Can anyone shed some light into this area? many thanks for your help.

    the following is the code:

    Private Sub CommandButton1_Click()
    Application.DisplayAlerts = False
    SaveFile.Close
    Application.DisplayAlerts = True
    End Sub

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: workbook close trigger unloading and termination of user forms.

    Hi there,

    Here's a knee-jerk and completely untested suggestion which should disable any events associated with closing the "SaveFile" workbook:

    Please Login or Register  to view this content.

    Hope this helps.

    Regards,

    Greg M

  3. #3
    Registered User
    Join Date
    06-10-2021
    Location
    Sdyney, Australia
    MS-Off Ver
    Excel 365, Excel 2010
    Posts
    10

    Re: workbook close trigger unloading and termination of user forms.

    hi Greg M, thank you for your quick reply and suggestion. but I am afraid that solution would not work for me, and maybe because I did not make myself clear in the first post.

    I want the command of "SaveFile.Close" to always run with no exceptions, and there is no situation where I need to set "false" for EnableEvents. To be clearer, my observation is this code "SaveFile.Close" runs differently in Excel 2010 and Excel 365, as detailed below:

    1. in excel 2010, "SaveFile.Close" simply close out that workbook namely "savefile", no more no less, which works fine for me in years for 2010 and older versions like excel 2003 or even older.

    2. In excel 365, "SaveFile.Close" close out the file, does the same as in excel 2010, but also continue to run further and mysteriously trigger other steps:

    a. unload all user forms. (all these user forms are stored in another master file of the macro program, not in the "savefile", so by right, closing out "savefile" shall not unload userforms. )

    b. because the program unloaded all the userforms, the program will run Initialize Event of the UserForms when program redo "userform.show" (a needed step).

    c. in the initialize event of userform, there is a coding to zero all textboxes and checkboxes, as needed for the program usage, but such a "zeroing" function must run only at the first time. In other works, for the 2nd and subsequent times of "userform.show", all the values in textboxes and checkboxes shall be maintained.

    so with my limited knowledge of VBA coding, I think excel 365 runs differently under the command of "workbook. close" comparing to excel 2010, and I wonder if anyone came cross a similar issue and had any solutions. Maybe a substitute code/ command in excel 365 does the closing workbook function only without mistriggering anything else, just like what excel 2010 does.

    Any help or hints would be highly appreciated.

    Regards
    Ben

  4. #4
    Registered User
    Join Date
    06-10-2021
    Location
    Sdyney, Australia
    MS-Off Ver
    Excel 365, Excel 2010
    Posts
    10

    Re: workbook close trigger unloading and termination of user forms.

    please see above.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Workbook crashing with user forms on Windows 10 due to possibly FM20.DLL?
    By TomA4986 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-14-2020, 08:59 PM
  2. Creating a termination liability workbook
    By anatrail74 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2020, 04:38 AM
  3. Event save on new excel workbook to trigger an existing macro elsewhere
    By jasath in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-12-2016, 08:25 PM
  4. A change to any cell in column I will trigger workbook.save
    By hensucker in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-29-2012, 11:22 AM
  5. Unloading Forms
    By dfaunce83 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-27-2012, 11:55 AM
  6. Loading and unloading user forms
    By sentinela in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-27-2009, 12:38 PM
  7. [SOLVED] Is there a way to Trigger a Macro on a workbook save event
    By Dan Gardner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-18-2005, 11:06 PM

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