title: Why do I get a "We found a problem with some content in '.xlsm'" message, everytime I automatically calculate a sheet?
body: <p>I have a piece of code that is extracting calendar events from A google calendar that is connected to my excel. It runs perfectly, however every time I add code to update a certain sheet("Calendar"), save, and close. I am prompted with the following message the next time I open the file again:
  We found a problem with some content in '.xlsm'. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes.</p>
  
  <p>Note this only happens when I add: Sheets("Calendar").Calculate, or Application.Calculation = xlAutomatic for the workbook. I also tried introducing a checkbox and only if the check box is checked and the macro is ran the sheet will be updated. That prompted the same error. When there is no calculate code this message does not pop up.</p>
  
  <p>I am baffled and couldn't find a similar situation with a sheet calculating being the cause. I appreciate any help.</p>
  
  <p>None of the code gets lost or altered, the file just comes up as [Repaired]</p>
  
  <pre><code>    Sub listlist()
  Dim olApp As Object, olNS As Object, olFolder As Object, olApt As Object, NextRow As Long, FromDate As Date, ToDate As Date, z As Integer, num As Integer
  Sheets("Calendar").Columns("A:B").ClearContents
  
  num = ActiveSheet.Cells(1, 1).Value - month(Now)
  FromDate = WorksheetFunction.EoMonth(Date, 0 + num) + 1
  ToDate = WorksheetFunction.EoMonth(Date, 1 + num)
  
  
  On Error Resume Next
  Set olApp = GetObject(, "Outlook.Application")
  If Err.Number &gt; 0 Then Set olApp = CreateObject("Outlook.Application")
  On Error GoTo 0
  
  Set olNS = olApp.GetNamespace("MAPI")
  Set olFolder = olNS.Folders("Internet Calendars").Folders("Calend")
  
  NextRow = 2
  
  
  With Sheets("Calendar")
      .Range("A1:C1").Value = Array("Project", "Date", "First Trim")
      For Each olApt In olFolder.Items
          If (olApt.Start &gt;= FromDate And olApt.Start &lt;= ToDate) Then
              .Cells(NextRow, "A").Value = olApt.subject
              .Cells(NextRow, "B").Value = CDate(olApt.Start)
              NextRow = NextRow + 1
          Else
          End If
      Next olApt
      .Columns.AutoFit
  End With
  
  Set olApt = Nothing
  Set olFolder = Nothing
  Set olNS = Nothing
  Set olApp = Nothing
  
  'Sort
  Dim Lastrow As Integer
  Lastrow = Sheets("Calendar").Cells(Rows.Count, 1).End(xlUp).Row
  Worksheets("Calendar").Sort.SortFields.Add2 Key:=Range("B2").End(xlDown) _
      , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  With Worksheets("Calendar").Sort
      .SetRange Range(Cells(1, 1), Cells(Lastrow, 3))
      .Header = xlYes
      .Orientation = xlTopToBottom
      .SortMethod = xlPinYin
      .Apply
  End With
  
  
  Sheets("Calendar").Calculate
  
  
  'Update Meeting dates
  
      z = 3
  
      For j = 2 To 20
          If Sheets("Calendar").Cells(j, 5).Value &lt;&gt; "" Then
          For I = 2 To 160
              If Sheets("Consultants").Cells(I, 15).Value = Sheets("Calendar").Cells(j, 5).Value Then
                  For h = 9 To 160
                      If Sheets("Consultants").Cells(I, 1).Value = ActiveSheet.Cells(h, 2).Value Then
                          ActiveSheet.Cells(h, 4).Value = Sheets("Calendar").Cells(j, 2).Value
                          Exit For
                      End If
                  Next h
              End If
          Next I
          End If
      Next j
  
  End Sub
  </code></pre>