title: VBA script why not runnable via command line
body: <p>I need to run this script outside excel, via powershell/command line.
  But I don't know why in excel works propertly as a macro and outside as .vbs via command line a lot of errors happens.
  How can I convert it or use this script via command line?
  Thanks</p>
  <pre><code>Sub csvToXLS(SourcePath, SheetOutput)
      Sheets.Add.Name = SheetOutput
      Sheets(SheetOutput).Select
  
  '    Open SourcePath For Input As #1
      Open &quot;C:\temp\Estrattore\2022_07_01-Report123.csv&quot; For Input As #1
      row_number = 0
      
      Do Until EOF(1)
          Line Input #1, LineFromFile
          LineItems = Split(LineFromFile, &quot;;&quot;)
          ActiveCell.Offset(row_number, 0).Value = LineItems(0)       ' Il nostro CSV prevede 7 campi (da 0 a 6)
          ActiveCell.Offset(row_number, 1).Value = LineItems(1)
          ActiveCell.Offset(row_number, 2).Value = LineItems(2)
          ActiveCell.Offset(row_number, 3).Value = LineItems(3)
          ActiveCell.Offset(row_number, 4).Value = LineItems(4)
          ActiveCell.Offset(row_number, 5).Value = LineItems(5)
          ActiveCell.Offset(row_number, 6).Value = LineItems(6)
          row_number = row_number + 1
      Loop
      Close #1
      
      Sheets(SheetOutput).Rows(1).AutoFilter                          ' Imposto il filtro automatico
      Sheets(SheetOutput).Rows(1).Interior.ColorIndex = 31            ' Coloro la prima riga
      Worksheets(SheetOutput).Columns(&quot;A:I&quot;).AutoFit                  ' Imposto l'autofit, ovvero la colonna ha dimensione tale da mostrare ogni risultato
      ActiveWindow.FreezePanes = False                                ' first, ensure that no panes are frozen
      Rows(&quot;2:2&quot;).Select                                              ' select the row that you want to freeze based on
      ActiveWindow.FreezePanes = True                                 ' freeze panes
  
  
  End Sub
  
  Sub main()
      Call csvToXLS(&quot;C:\temp\Estrattore\2022_07_01-Report1.csv&quot;, &quot;Report1&quot;)
      Call csvToXLS(&quot;C:\temp\Estrattore\2022_07_01-Report2.csv&quot;, &quot;Report2&quot;)
      Call csvToXLS(&quot;C:\temp\Estrattore\2022_07_01-Report3.csv&quot;, &quot;Report3&quot;)
      Call csvToXLS(&quot;C:\temp\Estrattore\2022_07_01-Report123.csv&quot;, &quot;Report123&quot;)
  End Sub
  </code></pre>