Forum Discussion

cindy_lu's avatar
cindy_lu
Copper Contributor
Aug 02, 2022
Solved

AppActivate give out error: "runtime error #5" if workbooks are added while ScreenUpdating = False

The following code will give out error. Can someone tells me why this error occurs? 😞   I found out that I can avoid error by not setting `ScreenUpdating = False` during Workbooks.Add. But in my...
  • JKPieterse's avatar
    JKPieterse
    Aug 02, 2022

    cindy_lu OK. I tried this and it appears to work:

    Sub test()
        Dim cap As String
        cap = Application.Caption
        Application.ScreenUpdating = False
        Application.Wait (Now + TimeValue("0:00:05"))
        Workbooks.Add
        Application.ScreenUpdating = True
        AppActivate cap
    End Sub
    

Resources