+ Reply to Thread
Results 1 to 9 of 9

MsgBox / popups freezes Excel

  1. #1
    Registered User
    Join Date
    02-03-2015
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    5

    MsgBox / popups freezes Excel

    I have a problem since a few weeks whereby both MsgBox and the popup from Application.GetOpenFilename() freeze Excel. It seems to be a general popup issue, and it does not matter where in the code it is. And it only happens after I run the macro for the third or fourth time. I keep having to force quit (through task manager), then restart Excel, and then inevitably after 3 or 4 runs it happens again. Could it be the size of my macro code? (I have around 3600 lines, although the code for any specific macro I run is just several hundred lines of code). What happens is when the popup appears, I can no longer select my spreadsheet and see the popup (when I click on the window, nothing happens). Sometimes after I click on the VB editor, I can go back to the spreadsheet and I can see the popup, but nothing happens when I click on it. I have this for several macros, so it doesn't seem related to a specific macro.

    I tried uninstalling and reinstalling Excel. And I tried both 32 bit and 64 bit. The problem remains. I am using Windows 8 with Excel 2013 Home & Student edition. Thanks for any ideas!
    Last edited by samexca; 02-03-2015 at 10:26 AM.

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: MsgBox / popups freezes Excel

    3600 lines of code sounds... ineffecient.
    Do you turn off events and screenupdating etc while running the code to speed it up?

    Can you give an example of code that will definitely crash after a few times?

  3. #3
    Registered User
    Join Date
    02-03-2015
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: MsgBox / popups freezes Excel

    The code could definitely be more efficient, but a lot of code is unavoidable - there's around 25 different functions that need to be performed, each ranging from several lines to up to around 700 lines of code for the largest.

    An example of where it gets stuck is the following: (you can see it turns off events, screenupdating, etc.). This might run around 6-7 times at best, or sometimes just 3-4 times before it crashes with the popup. The popup in this case is right at the beginning of the code. This particular macro is around 400 lines of code.

    Sub importDataCustom()
    Dim bEvents As Boolean
    Dim bAlerts As Boolean
    Dim CalcMode As Long
    Dim bScreen As Boolean

    ' save current settings
    bEvents = Application.EnableEvents
    bAlerts = Application.DisplayAlerts
    CalcMode = Application.Calculation
    bScreen = Application.ScreenUpdating

    ' disable events, alerts, automatic calculation & screen updating
    With Application
    .EnableEvents = False
    .DisplayAlerts = False
    .Calculation = xlCalculationManual
    .ScreenUpdating = False
    End With

    LoadVars 'this runs another Sub of 50 lines of code, which grabs various variable values from the current sheet

    Dim categoryNames(500) As String
    Dim indicIDArray(0 To 10000, 0 To 1) As String
    Dim categoryNamesCounter As Integer
    Dim indicIDCounter As Integer

    ProgramWorkbook = ActiveWorkbook.Name
    DataFile = Application.GetOpenFilename("Data files, *.*", , "Please select a file containing the data you wish to import.")
    If DataFile = False Then
    End
    End If

    ...freezes with this popup

  4. #4
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: MsgBox / popups freezes Excel

    Try to set screenupdating to true and add a 'doevents' before the "ProgramWorkbook = ActiveWorkbook.Name" and then turn off screenupdating again after the popup is closed.
    Without seeing more, that's the only thing I can come up with.
    Please click the * below if this helps

  5. #5
    Registered User
    Join Date
    02-03-2015
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: MsgBox / popups freezes Excel

    Thanks, I will give that a go!

  6. #6
    Registered User
    Join Date
    02-03-2015
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: MsgBox / popups freezes Excel

    Just to let you know that this appears to have resolved it, so thanks very much for your help! I had to do that for every single popup. Now I just have Excel freezing when there is an error in the code - so an unexpected popup.

  7. #7
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: MsgBox / popups freezes Excel

    To prevent that, include an error exit strategy;

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    02-03-2015
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: MsgBox / popups freezes Excel

    Thanks for that solution. It's a pity it loses the line number of the regular error message though. Do you know if it is still possible to show the regular error message with the debug button, in order to go to the line where the error occurs?

  9. #9
    Registered User
    Join Date
    06-09-2020
    Location
    Belgium
    MS-Off Ver
    Professional Plus 2016
    Posts
    1

    Re: MsgBox / popups freezes Excel

    In my case the freeze is not a result of an error. imho it is purely related to the MsgBox that should be brought up. No fancy code around it.
    I get my error in several excel files with completely unrelated code. The common part is "Show me that MsgBox"

    I could find one stupid and not guaranteed way around it:
    - Open Windows Taks Manager,
    - kill dwm.exe and
    - wait until my screen refreshes.
    - Next, try to be with your mouse cursor in the area where the MsgBox shall be and start to click franticly... IF you hit one of the (hidden? or freshly popped up?) MsgBox buttons, then the macros run further.
    Sometimes I have to kill dwm.exe multiple times to pass this blocking stage.
    It looks to me that the MsgBox is 1. not popping up 2. stays invisible 3. ...???

    I also have tried to implement the MsgBox using a timeout timer... thinking it IS there, but not accessible, but even in that case the MsgBox is not brought up and the timer doesn't start to run. (found that code on stackoverflow and it works fine... but it doesn't solve the problem I describe here, also that code blocks (display-a-message-box-with-a-timeout-value))

    Anybody experiencing this thing and has a good explanation and/or solution to it?

+ 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. Excel Freezes
    By zachdking in forum Excel General
    Replies: 23
    Last Post: 11-11-2013, 12:06 PM
  2. Replies: 1
    Last Post: 07-17-2013, 08:10 AM
  3. Replies: 3
    Last Post: 07-17-2013, 08:10 AM
  4. creating alerts!or popups in excel
    By mailboxsurya in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-09-2005, 08:31 PM
  5. creating alerts!or popups in excel
    By mailboxsurya in forum Excel General
    Replies: 1
    Last Post: 05-09-2005, 02:15 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