Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88030

Error : SaveAs method of Workbook class failed

$
0
0
Dim app, fso, file, fName, wb, dir 

dir = "D:\TA"

dirsave = "D:\TA\XLS"

Set app = CreateObject("Excel.Application")
Set fso = CreateObject("Scripting.FileSystemObject")

For Each file In fso.GetFolder(dir).Files
    If LCase(fso.GetExtensionName(file)) = "csv" Then  
    fName = fso.GetBaseName(file)

    Set wb = app.Workbooks.Open(file) 
    app.Application.Visible = True
    app.Application.DisplayAlerts = False
    app.ActiveWorkbook.SaveAs dirsave & fName & ".xls", 43
    app.ActiveWorkbook.Close 
    app.Application.DisplayAlerts = True 
    app.Application.Quit 

    End if
Next

Set fso = Nothing
Set wb = Nothing    
Set app = Nothing

wScript.Quit

I am using above VB script to open csv file and save it as xls file but it throws error

Error : SaveAs method of Workbook class failed.

How can I fix it? Thanks in advance


Viewing all articles
Browse latest Browse all 88030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>