0

I am trying to run the following code from a .vbs file under Windows, but cannot get it to run. I have added some commands from a macro I recorded, and apparently that does not work. Could you point me in the right direction? (I realize this must be a trivial problem)

Set fso = CreateObject("Scripting.FileSystemObject")
Set xl  = CreateObject("Excel.Application")
xl.Visible = True

For Each f In fso.GetFolder("C:\Temp").Files
  If LCase(fso.GetExtensionName(f.Name)) = "xlsm" Then
    Set wb = xl.Workbooks.Open(f.Path)
    Set ws = wb.Worksheets("Data")
    ' make sure number formatting is OK
    ws.Cells.Select
    ws.Selection.NumberFormat = "General"
    ' kill header row
    ws.Rows("1:1").Select
    ws.Selection.Delete Shift:=xlUp
    ' save output as CSV
    wb.SaveAs Filename:= f.Path & ".csv", FileFormat:= xlCSVMSDOS, CreateBackup:=False
    wb.Close
  End If
Next

xl.Quit
user1769925
  • 588
  • 1
  • 6
  • 15

1 Answers1

0

VBScript does neither supports named arguments nor xl* constant as in your:

ws.Selection.Delete Shift:=xlUp

See named/positional args, consts, other.

Community
  • 1
  • 1
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96