Error saying "ActiveX can't create component" with hidden excel workbook

32 Views Asked by At

So, I have an Excel workbook that, when it opens, launches a userform and hides the workbook application window with this code:

Private Sub Workbook_Open()
    Dim ws As Worksheet
 
    ThisWorkbook.Worksheets("MODULE BUTTON").Activate

        For Each ws In ThisWorkbook.Sheets
        If ws.Name <> "MODULE BUTTON" Then
            ws.Visible = xlSheetHidden
        End If
    Next ws

ThisWorkbook.Sheets("MODULE BUTTON").Visible = xlSheetVisible

    Application.Visible = False
  
 Mark1.Show vbModeless
End Sub

When I close my userform, it saves and closes the hidden workbook with this code:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
ThisWorkbook.Save
       
ThisWorbook.Close

End Sub

However, the next time I go to launch the workbook, it says "ActiveX component can't create object" on line Mark1.Show vbModeless. Mark1 is the userform. However, once I close it again and reopen it, it opens just fine.

I tried to change the code in the query close to Application.quit, which fixed the issue, but it also closes every Excel window and sometimes my users have other Excel files open simultaneously.

Any ideas on what I am missing here?

Edit: I pasted my second code and not the original. The problem I originally had was with ThisWorkbook.Close, and changed it to Application.Quit.

0

There are 0 best solutions below