0
votes

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
1
Have you already tried anything yourself to delete the files? It's not that this feature is hidden or undocumented. - Tomalak
i'm unfamiliar with the process, hence why i'm asking for advice. i didn't write this script, it was already in place, and i'm being asked to amend it. - chenks
Yes, but the purpose of this website is not to find someone who does your work. Please do a minimum of research and try to fix this yourself. Code samples of how to use VBScript to delete files are literally all over the internet, you just have not even tried so far. - Tomalak
thanks for your constructive input. you haven't commented on the other question i asked regarding the missing XLS file extension. - chenks
OK i added fs.DeleteFile("C:\test\xml*.xml") to the script which appears to do it, whether that is the most efficient way of doing it, i don't know. - chenks

1 Answers

0
votes

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"