Open, save and close Ms Excel through vbs

strPath = “D:\M7Regression\AutomationTool\MFAST\7.0\TestData”

Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True
objExcel.DisplayAlerts = False

Set objFso = CreateObject(“Scripting.FileSystemObject”)
Set objFolder = objFso.GetFolder (strPath)

For Each objFile In objFolder.Files

If objFso.GetExtensionName (objFile.Path) = “xls” OR objFso.GetExtensionName (objFile.Path) = “xlsx” Then
Set objWorkbook = objExcel.Workbooks.Open(objFile.Path)
‘objWorkbook.Open
objWorkbook.Save
objWorkbook.Close True ‘Save changes
End If

Next

objExcel.Quit

Leave a comment