Question

I have a VBScript that opens any XML files in one folder and saves them as excel files to another folder.

it seems to work, although the resulting excel files have no XLS extension, any ideas why ?

what i would like the script to then do is delete all the files from the sourcefolder. how would i do this?

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
Was it helpful?

Solution

Files gets no extension because you are not giving it.

Output file is

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

GetBaseName doesn't include extension. Just add the extension

TargetFolder & "\" & fs.GetBaseName( file ) & ".xls" 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top