从 VBS 脚本运行 Excel [英] Running Excel from VBS script

查看:28
本文介绍了从 VBS 脚本运行 Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

VBScript 既不支持命名参数也不支持 xl* 常量,如您的:

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

ws.Selection.Delete Shift:=xlUp

参见命名/位置参数常量其他一>.

这篇关于从 VBS 脚本运行 Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆