Micro Focus QTP (UFT) Forums
Excel Save as Method - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Excel Save as Method (/Thread-Excel-Save-as-Method)



Excel Save as Method - chanda Hemke - 06-21-2010

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



RE: Excel Save as Method - sreekanth chilam - 06-21-2010

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



RE: Excel Save as Method - chanda Hemke - 06-21-2010

well thnks for reply..but its not wrking..is there any option like:-

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


RE: Excel Save as Method - vijayendra.shukla - 06-23-2010

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