title: ThisWorkbook Not Working in Excel 2018?
body: <p>I have recently encountered a problem where a macro that used to work in previous versions of Excel has stopped functioning as intended. The macro, when functional, opens each file in a specific folder and copies some of its data and pastes it into another file which it opened.</p>
  
  <p>Since this macro is run from within a file in the folder, it was previously programmed to not attempt to re-open the file, using the code below:</p>
  
  <pre><code>' Create a new workbook and set a variable to the first sheet.
    '  Set SummarySheet =
      Workbooks.Open ("[Redacted]")
     '     agg_wkb_name = ActiveWorkbook
          lrowcount = ActiveWorkbook.Worksheets("scheduled hours").UsedRange.Rows.Count
          ActiveWorkbook.Worksheets("scheduled hours").Range("A2:bz" &amp; lrowcount).Delete
      ' Modify this folder path to point to the files you want to use.
      FolderPath = "[Redacted]"
  
      ' NRow keeps track of where to insert new rows in the destination workbook.
      NRow = 2
  
      ' Call Dir the first time, pointing it to all Excel files in the folder path.
      FileName = Dir(FolderPath &amp; "*.xl*")
  
      ' Loop until Dir returns an empty string.
      Do While FileName &lt;&gt; ""
          ' Open a workbook in the folder
          If FolderPath &amp; FileName = ThisWorkbook.FullName Then
          Set WorkBk = ThisWorkbook
          Else
          Set WorkBk = Workbooks.Open(FolderPath &amp; FileName, , True)
          End If
  </code></pre>
  
  <p>However, after our computers and programs were updated to Win10 and Excel 2016, this macro began attempting to also open the workbook running the file ('ThisWorkbook'). When you attempt to say "no, I don't want to re-open the file", it stops the Macro, and when you say "yes", Excel crashes. </p>
  
  <p>I attempted to segregate the code, to pull the data from 'ThisWorkbook' differently than pulling it from the various other workbooks in the folder. The new section of code reads:</p>
  
  <pre><code>Do While FileName &lt;&gt; ""
          If Not (FolderPath &amp; FileName = ThisWorkbook.Path &amp; ThisWorkbook.Name) Then
          Set WorkBk = Workbooks.Open(FolderPath &amp; FileName, , True)
          End If
  </code></pre>
  
  <p>Unfortunately, the very same error still occurs. I'm at a loss - my best guess is that something changed in the way 'ThisWorkbook' functions between the last version of Excel and the current one. </p>