Blocking cell editing after using msgbox

73 Views Asked by At

I have a workbook with various improvements (macro, formulas). By default, the workbook opens in full screen mode.

Private Sub Workbook Open ()
    Application.DisplayFullScreen = True   
End Sub

Recently I added an activeX button. This button appears if the specified cell is not empty. The worksheet_ change event is responsible for this.

Private SubWorksheet_Change(ByVal Target As Range)
    Application.ScreenUpdating = False
    If Range ("B47").Value <> "" Then 
        Me.Totalvalue.Visible = True   
    Else 
        Me.Totalvalue.Visible = False
    End If
    Application.ScreenUpdating = True 
End Sub

Using the button brings up a message box. Message box displays the content and number of the specified cell.
After closing the message box, the spreadsheet cells are inactive. It is not possible to edit the data.

Only form controls, activeX controls, and drop-down lists are active. The delete and escape keys also help. However, using esc exits full screen mode.
Interestingly, this problem does not occur unless the sheet is in full screen mode.

Please help me and indicate what may cause the problem of blocking cell editing

I made these last changes in another file and everything works fine. Unfortunately, the file with the problem is too extensive (formulas, macros, userforms, conditional formatting) for me to do it from scratch

2

There are 2 best solutions below

1
CHill60 On

See stackoverflow answers at vba - Excel Full screen mode can't edit cell

Basically the solutions there suggest selecting another sheet then going back to your selected sheet. You can do this in code.

Some locations will experience issues with ActiveX controls depending on version and update status of Windows - I removed all ActiveX controls from our EUC for this reason (replaced with Forms controls)

Finally - is this full screen on your main monitor - some strange behaviours can also occur if you have full screen on an extended monitor - buttons may work on one screen but not the other (strange but true)

EDIT: To answer your questions in your comment below

Yes it is possible to hide a Form Control Button on a sheet e.g. if I have a button I have named "btnNamed"

Dim btn As Object
Set btn = ThisWorkbook.Sheets(1).Buttons("btnNamed")
btn.Visible = False

You can also refer to the button by index 1, 2 etc. Not sure how that relates to this question though.

I never suggested using Range("A1").ClearContents so I can't help you with that. I can't see how that could possibly work.

If a MsgBox is still on the screen then editing will be blocked until you have dismissed the MsgBox I.e. the user has hit Enter or Esc.

The accepted solution on the link I gave above does not mention the delete key nor the formula bar. It suggests selecting another sheet, then going back to your original sheet e.g.

With ThisWorkbook
    .Sheets(1).Select
    MsgBox "a message"
    'Code is paused until I hit enter
    .Sheets(2).Select
    .Sheets(1).Select
End With
0
Grzegorz On

I modified the code as indicated. I introduced selecting another sheet and returning to the original one and unfortunately it did not solve the problem of blocking cell editing.

If I removed the Msgbox code, the sheets switched. It turns out that the blocking is not caused only by the ActiveX control and full screen, without the formula bar, but by the presence of Msgbox in the ActiveX code.

Only removing the ActiveX control and inserting a form control solved the problem.

Thank you very much for your help and showing me how to hide the form control.