title: Excel VBA Code Save and Close
body: <p>I want to loop through 2000 csv files, convert them to xls, make changes to the spreadsheet.</p>
  
  <p>I can't work out how to save and close the workbook before moving on to the next.</p>
  
  <p>I tried the following at the end of the script. </p>
  
  <pre><code>Application.ActiveWindow.Close SaveChanges:=False
  ActiveWorkbook.Close SaveChanges:=False
  </code></pre>
  
  <p>I get a Minor loss of fidelity message.</p>
  
  <p>The full code</p>
  
  <pre><code>Sub batchconvertcsvxls()
  Dim wb As Workbook
  Dim strFile As String, strDir As String, strOut_Dir As String, myNewFileName As String
  
  strDir = "C:\csv\" 'location of csv files
  strOut_Dir = "C:\converted\" 'location of xls files
  strFile = Dir(strDir &amp; "*.csv")
  
  Do While strFile &lt;&gt; ""
  
  Set wb = Workbooks.Open(filename:=strDir &amp; strFile, Local:=True)
  
      With wb
          .SaveAs strOut_Dir &amp; Replace(wb.Name, ".csv", ".xls"), 56
          .Close True
      End With
  Set wb = Nothing
  
  Set wb = Workbooks.Open(filename:=strOut_Dir &amp; Replace(strFile, ".csv", ".xls"))
  
  Rows("1:1").Select
  With Selection.Interior
      .Pattern = xlSolid
      .PatternColorIndex = xlAutomatic
      .ThemeColor = xlThemeColorDark2
      .TintAndShade = -0.249977111117893
      .PatternTintAndShade = 0
  End With
  Selection.RowHeight = 60
  Selection.ColumnWidth = 30
  With Selection
      .HorizontalAlignment = xlGeneral
      .VerticalAlignment = xlBottom
      .WrapText = True
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = False
  End With
  With Selection
      .HorizontalAlignment = xlGeneral
      .VerticalAlignment = xlTop
      .WrapText = True
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = False
  End With
  Columns("E:E").Select
  With Selection
      .HorizontalAlignment = xlLeft
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = False
  End With
  Cells.Select
  Selection.AutoFilter
  Range("E2").Select
  ActiveWindow.FreezePanes = True
  
  For i = 1 To ActiveSheet.UsedRange.Columns.Count
  
      DataFound = False
      j = 2
      While DataFound = False And j &lt;= ActiveSheet.UsedRange.Rows.Count
          If Cells(j, i).Value &lt;&gt; "" Then
              DataFound = True
          End If
          j = j + 1
      Wend
      If DataFound = False Then
          Columns(i).Hidden = True
      End If
  Next
  
  strFile = Dir
  
  Application.ActiveWindow.Close SaveChanges:=True ActiveWorkbook.Close
  SaveChanges:=False
  
  Loop
  
  End Sub
  </code></pre>