title: With Block Variable not Set -- Error when workbook Opened
body: <p>This macro is one that was not written by me, so I'm having trouble understanding the source of the error. I have a macro that's supposed to run on startup to adjust the ribbon to add a button, and another part to remove styles when you select that button. Currently, I get the message: <code>Object variable or With block variable not set</code>. When I select "Debug" it goes to the VBA screen and immediately gives me 3 more error pop-ups that say: <code>Can't execute code in break mode</code>.</p>
  
  <p>The first part of this is the two subs that are to run on startup, which are:</p>
  
  <pre><code>Dim WithEvents app As Application
  
  Private Sub App_WorkbookActivate(ByVal Wb As Workbook)
    Module1.MyRibbon.Invalidate
  End Sub
  
  Private Sub Workbook_Open()
    Set app = Application
  End Sub
  </code></pre>
  
  <p>It highlights the <code>Module1.MyRibbon.Invalidate</code>as the problematic bit. Personally I don't see anything wrong with this per se, but perhaps the problem is in the Module 1? That code contains three subs, as follows:</p>
  
  <pre><code>Public MyRibbon As IRibbonUI
  'Callback for customUI.onLoad
  Sub CallbackOnLoad(Ribbon As IRibbonUI)
      Set MyRibbon = Ribbon
  End Sub
  
  
  'Callback for customButton getLabel
  Sub GetButtonLabel(control As IRibbonControl, ByRef returnedVal)
     If ActiveWorkbook Is Nothing Then
          returnedVal = "Remove Styles"
     Else
          returnedVal = "Remove Styles" &amp; vbCr &amp;  
             Format(ActiveWorkbook.Styles.Count, "#" &amp; Application.International(xlThousandsSeparator) &amp; "##0")
     End If
  End Sub
  
  
  Sub RemoveTheStyles(control As IRibbonControl)
      Dim s As Style, i As Long, c As Long
      On Error Resume Next
      If ActiveWorkbook.MultiUserEditing Then
          If MsgBox("You cannot remove Styles in a Shared workbook." &amp; vbCr &amp; vbCr &amp; _
                "Do you want to unshare the workbook?", vbYesNo + vbInformation) = vbYes Then
          ActiveWorkbook.ExclusiveAccess
             If Err.Description = "Application-defined or object-defined error" Then
                 Exit Sub
             End If
          Else
             Exit Sub
          End If
      End If
      c = ActiveWorkbook.Styles.Count
      Application.ScreenUpdating = False
      For i = c To 1 Step -1
         If i Mod 600 = 0 Then DoEvents
         Set s = ActiveWorkbook.Styles(i)
         Application.StatusBar = "Deleting " &amp; c - i + 1 &amp; " of " &amp; c &amp; " " &amp; s.Name
         If Not s.BuiltIn Then
             s.Delete
             If Err.Description = "You cannot use this command on a protected sheet. To use this command, you must first unprotect the sheet (Review tab, Changes group, Unprotect Sheet button). You may be prompted for a password." Then
              MsgBox Err.Description &amp; vbCr &amp; "You have to unprotect all of the sheets in the workbook to remove styles.", vbExclamation, "Remove Styles AddIn"
                 Exit For
             End If
          End If
      Next
      Application.ScreenUpdating = True
      Application.StatusBar = False
  End Sub
  </code></pre>
  
  <p>I've never written any Activation or Ribbon-related macro, so I have no idea where the error could be. The addin works just find regardless of this message, as the button gets added and it functions as it should when the file isn't a blank file, but I get the error pop-up and the button doesn't get created right on new, blank files. How could I fix this?</p>