从VBScript运行Excel

时间:2015-04-10 08:53:11

标签: excel vbscript

我正在尝试从Windows下的.vbs文件运行以下代码,但无法运行它。我已经从我录制的宏中添加了一些命令,显然这不起作用。你能指出我正确的方向吗? (我意识到这一定是一个微不足道的问题)

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

1 个答案:

答案 0 :(得分:0)

VBScript既不支持命名参数也不支持xl * constant,如下所示:

ws.Selection.Delete Shift:=xlUp

请参阅named/positional argsconstsother