0

我有一个 VBScript,可以打开一个文件夹中的任何 XML 文件并将它们作为 excel 文件保存到另一个文件夹。

它似乎有效,虽然生成的 excel 文件没有 XLS 扩展名,但有什么想法吗?

然后我希望脚本做的是从源文件夹中删除所有文件。我该怎么做?

Dim xlApp, xlWkb, SourceFolder,TargetFolder,file
Set xlApp = CreateObject("excel.application")
set fs = CreateObject("Scripting.FileSystemObject")
Const xlNormal=1
SourceFolder="c:\test\xml"
TargetFolder="c:\test\xls"

'Hide Excel
xlApp.Visible = false

'Process each file in SourceFolder
for each file in fs.GetFolder(SourceFolder).files
'Open file in SourceFolder
Set xlWkb = xlApp.Workbooks.Open(file)
'Get Filename
BaseName= fs.getbasename(file)
'Concatenate full path. Extension will be automatically added by Excel
FullTargetPath=TargetFolder & "\" & BaseName
'Save as XLS file into TargetFolder
xlWkb.SaveAs FullTargetPath, xlNormal
'Close file
xlWkb.close
next

Set xlWkb = Nothing
Set xlApp = Nothing
Set fs = Nothing
4

1 回答 1

0

文件没有扩展名,因为你没有给它。

输出文件是

TargetFolder & "\" & fs.GetBaseName( file )

GetBaseName 不包括扩展名。只需添加扩展名

TargetFolder & "\" & fs.GetBaseName( file ) & ".xls" 
于 2013-10-14T16:21:29.377 回答