Micro Focus QTP (UFT) Forums

Full Version: Excel Save as Method
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How to replace existing excel file while using Save as Method ?
For ex:- In the following code if Newfile.xls already exist ,it gives me alert "Do u want to replace it?" .

Code:
TestSuitFileLocation="H:"
TestSuitFileName="H:\Book.xls"
TestSuitFileNewName="NewFile.xls"
    Set excelApp = CreateObject("Excel.Application")
    excelApp.Visible = true
    Set TestSuiteExcelFile = excelApp.Workbooks.Open (TestSuitFileName)    
    TestSuiteExcelFile.SaveAs TestSuitFileLocation& "\"&TestSuitFileNewName
    TestSuiteExcelFile.close
    excelApp.quit
    Set excelApp = Nothing
Hi Chanda,

Check with the belw code:
Code:
TestSuitFileLocation="H:"
TestSuitFileName="H:\Book.xls"
TestSuitFileNewName="NewFile.xls"
Set excelApp = CreateObject("Excel.Application")
excelApp.Visible = True
excelApp.Workbooks.Open (TestSuitFileName)
excelApp.ActiveWorkBook.SaveAs TestSuitFileLocation&"\"&TestSuitFileNewName
excelApp.quit
Set excelApp = Nothing
well thnks for reply..but its not wrking..is there any option like:-

TestSuiteExcelFile.SaveAs testSuitFileLocation& "\"&TestSuitFileNewName, true
Hi Chanda,

Use this code

Code:
TestSuitFileLocation = "H:"
TestSuitFileName = "H:\Book.xls"
TestSuitFileNewName = "NewFile.xls"
Set excelApp = CreateObject("Excel.Application")
excelApp.Visible = True
Set TestSuiteExcelFile = excelApp.Workbooks.Open(TestSuitFileName)
excelApp.DisplayAlerts = False
TestSuiteExcelFile.SaveAs TestSuitFileLocation & "\" & TestSuitFileNewName
TestSuiteExcelFile.Close
excelApp.DisplayAlerts = True
excelApp.Quit
Set excelApp = Nothing

Suppressing the alert messages (excelApp.DisplayAlerts = False and excelApp.DisplayAlerts = True) will save you the trouble.

HTH.

Cheers,
Vijayendra