从VBS脚本运行Excel [英] Running Excel from VBS script
本文介绍了从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屋!
查看全文