Routine hang over

MPW

Well-known Member
Joined
Oct 7, 2009
Messages
571
Office Version
  1. 365
Platform
  1. Windows
I have been using this routine to run before the save event. Recently I noticed that it is still running somehow after the fact. I use a hotkey to start a userform, but after I save the workbook I can not use the hotkey until I click stop in the VBA Editor. If I put a breakpoint at the beginning of the BeforeSave routine and click run, the problem does not manifest. let me know if you need more information.

Most of this code was written more than 15 years ago so if it doesn't make sense it was past me's fault!

It calls on some other small routines.
I have included them below
VBA Code:
Public Sub CORE_BeforeSave()
    
    HomeWard
    If allline = 0 Then
        TotallyAll           'Located in Module 1.
    End If
    Application.ScreenUpdating = False
    MakeWork
    Sheets("Script").Unprotect "0000"
    Dim oldate
    oldate = Sheets("Script").Range("K1")
    Application.EnableEvents = False
    On Error Resume Next
    If Navigator1.CommandButton3.Visible = True Then 'OK Button
        If Navigator1.TextBox1.Text <> "" Then
            Navigator1.CommandButton3.BackColor = RGB(0, 255, 0)
            Navigator1.CommandButton3.Enabled = True
        ElseIf Navigator1.TextBox1.Text = "" Then
            Navigator1.CommandButton3.BackColor = RGB(192, 192, 192)
            Navigator1.CommandButton3.Enabled = False
        End If
    End If
    If IsUserFormLoaded("EditLine") = True Then
        Unload EditLine
    End If
    Sheets("Script").Unprotect "0000"
    DoEvents
    Sheets("Script").Range("K1") = Now
    Navigator1.Label12.Caption = "Saved:  " & Format$(Now, "ddd  h:mm AM/PM") & "  " & Format$(Now, "mm.dd.yy")
    Navigator1.Label12.BackColor = RGB(102, 102, 153)
    Navigator1.Label12.ForeColor = RGB(255, 255, 204)
    Navigator1.CommandButton27.BackColor = RGB(255, 255, 153)
    Navigator1.CommandButton28.BackColor = RGB(255, 255, 153)
    MakeWork
    Sheets("Script").Protect Password:="0000", AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowFiltering:=True
    GoHome
    Application.ScreenUpdating = True
    
    
End Sub
Sub HomeWard()

    'Tracks the active cell location so that it can be returned to it by the gohome routine.
    If ActiveCell.Row > 56 Then
        OldRow = ActiveCell.Row
        OldColumn = ActiveCell.Column
    End If
End Sub
Sub TotallyAll()
    

    'Loads all of the ranges needed by the CORE-Script to modify large groups of cells.

    allline = Sheets("Script").Cells(Rows.Count, 2).End(xlUp).Row

    stA57A = "A57:A" & (allline) & ""
    stA57P = "A57:P" & allline & ""
    stB57B = "B57:B" & allline & ""
    stB57I = "B57:N" & allline & ""
    stB57N = "B57:N" & allline & ""
    stC57D = "C57:D" & allline & ""
    stD57F = "D57:F" & allline & ""
    stE57E = "E57:E" & allline & ""
    stE56F = "E56:F" & allline & ""
    stF57F = "F57:F" & allline & ""
    stG56G = "G56:G" & allline & ""
    stG57G = "G57:G" & allline & ""
    stG57H = "G57:H" & allline & ""
    stH57H = "H57:H" & allline & ""
    stI57I = "I57:I" & allline & ""
    stI57ILong = "I57:I" & (allline + 1) & ""
    stI58I = "I58:I" & allline & ""
    stJ56J = "J56:J" & allline & ""
    stJ57J = "J57:J" & allline & ""
    stK57K = "K57:K" & allline & ""
    stK57N = "K57:N" & allline & ""
    stK57L = "K57:L" & allline & ""
    stL57L = "L57:L" & allline & ""
    stM57M = "M57:M" & allline & ""
    stM57N = "M57:N" & allline & ""
    stN57N = "N57:N" & allline & ""
    stP57P = "P57:P" & allline & ""
    stP57S = "P57:T" & allline & ""
    stQ57Q = "Q57:Q" & allline & ""
    stQ57R = "Q57:R" & allline & ""
    stQ57T = "Q57:T" & allline & ""
    stR57R = "R57:R" & allline & ""
    stS57S = "S57:S" & allline & ""
    stT57T = "T57:T" & allline & ""

    stAA56AC = "AA56:AC" & allline & ""
    
    stmul1 = "A57:C" & allline & ",G57:H" & allline & ",J57:J" & allline & ",O57:P" & allline & ""
    stmul2 = "D4:D29" & ",K57:N" & allline & ""
    
End Sub

Sub MakeWork()
    
    Application.EnableEvents = True
    Application.Calculation = xlCalculationAutomatic
    
End Sub
Sub GoHome()
    If OldRow <> "" And OldColumn <> "" Then Cells(OldRow, OldColumn).Select
End Sub
Thanks for the look.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Ok, so I did some additional checking. What I found is that my problem has nothing to do with my routine.
I remmed out
VBA Code:
'Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
''    CORE_BeforeSave          'Located in Module 1.
'End Sub

My userform shows reliably when the hot keys are pressed, until I save the workbook. After that I will just get the "Exclamation" sound effect when I press the hot keys.
If I open the VBE and click stop the hot keys function normally.

If anyone has experience this and found a way past it I would like to know how to do it.
 
Upvote 0
Stranger still:
I have a button to save the workbook located in the main userform. If this save button is used then I can close the userform and reopen it normally.
However if I close the userform and save the workbook using Ctrl+S then the problem occurs.
Here is the code for the save button:
VBA Code:
    'Save Button Navigator1.CommandButton27
    Navigator1.CommandButton27.Caption = "Saving..."
    Navigator1.CommandButton27.Font.Bold = True

    Application.ActiveWorkbook.Save
    Sheets("Script").Range("K1") = Now
    Lockup
    Navigator1.CommandButton27.Font.Bold = False
    Navigator1.CommandButton27.Caption = "Save" & vbCrLf & "CORE-Script"
 
Upvote 0
More detail: If I use Ctrl+S while the userform is active then close it, it will open normally. If I close the userform and then use Ctrl+S the userform will not open. (until I stop macros in the VBE)

Another question would be, is there a way to see what is running in VBA during this hangup?
 
Upvote 0
After some more investigation I discovered several websites that spoke of glitches using Ctrl+Shift+whatever. My shortcut that I have been using is Ctrl+Shift+D. This has been used successfully for more than 5 years without issue. I would rather not change this shortcut since there are over 50 teams of people scattered all over the world using this. It would require a lot of retraining which can be difficult since it has been used so long. I would rather figure out a way to side step the issue if possible. I am not positive that this is the issue, but it makes more sense then anything else that I have found. Ideas?
 
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,228
Members
448,951
Latest member
jennlynn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top