Form Not Launching on Workbook_Open

breynolds0431

Board Regular
Joined
Feb 15, 2013
Messages
66
Hi. I have the below to launch a form when the workbook is opened. It works sometimes, but not always. When it's not working, it seems like the users need to close out all excel workbooks and open the book with the form - like it's clearing out some bugs in doing so. I thought maybe it had something to do with Enable Events, so I have it set to True. But that doesn't seem to be the case. Is there an apparent issue in the below code that I'm missing? Thanks for your time!

VBA Code:
Option Explicit

Private Sub Workbook_Open()

Sheets("-").Activate
wksProject.Visible = xlSheetVeryHidden
ThisWorkbook.Sheets("ProvLook").Visible = False

'Will run STAR update

    With Application
    
        .ScreenUpdating = False
        .DisplayAlerts = False
        .EnableEvents = True
    End With

    On Error GoTo FailedUpdate
    
    ThisWorkbook.Sheets("ProvLook").Visible = True
    
    wksProvLook.Select
    Range("A2").CurrentRegion.Select
    Selection.ClearContents

        Workbooks.Open Filename:= _
            "T:\*Full Path Removed*\TMFileData.xlsx", ReadOnly:=True
            
        Columns("A:H").Select
        Selection.Copy
        ThisWorkbook.Activate
        wksProvLook.Activate
        Range("A1").Select
        ActiveSheet.Paste
        Application.CutCopyMode = False
        Application.Goto Reference:="Updated"
        ActiveCell.FormulaR1C1 = "=NOW()"
        Range("Updated").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Range("A2").Select
        Workbooks("TMFileData.xlsx").Close savechanges:=False

    ThisWorkbook.Sheets("ProvLook").Visible = False
    
    On Error GoTo 0
    
    frmNewProject.Show

With Application
    
    .ScreenUpdating = True
    .DisplayAlerts = True
End With

Done:
    Exit Sub

FailedUpdate:

    frmNewProject.Show

    With Application
      .ScreenUpdating = True
      .DisplayAlerts = True
    End With

End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)

    wksProject.Visible = xlSheetVeryHidden

End Sub
 

Some videos you may like

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

CephasOz

Board Regular
Joined
Feb 18, 2020
Messages
205
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Try putting frmNewProject.Show after you turn screen updating back on.
 

Watch MrExcel Video

Forum statistics

Threads
1,114,116
Messages
5,546,030
Members
410,721
Latest member
adi772
Top