Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Excel Save as Method
#1
Solved: 10 Years, 9 Months, 2 Weeks ago
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
Reply
#2
Solved: 10 Years, 9 Months, 2 Weeks ago
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
Reply
#3
Solved: 10 Years, 9 Months, 2 Weeks ago
well thnks for reply..but its not wrking..is there any option like:-

TestSuiteExcelFile.SaveAs testSuitFileLocation& "\"&TestSuitFileNewName, true
Reply
#4
Solved: 10 Years, 9 Months, 2 Weeks ago
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  QTP 11.0 Doesn't allow to save excel extracted from BO report. Hema Ganesh.M 1 3,077 12-09-2013, 07:32 AM
Last Post: basanth27
  Get values from dropdown the. Save it to excel Sm8422 1 4,605 06-11-2012, 09:44 AM
Last Post: ravi.gajul
  Save or Save As not working for QTP 11 Nick 1 3,088 08-13-2011, 12:16 PM
Last Post: vaddevinod
  Save Excel file mv8167 4 27,550 07-14-2011, 02:19 AM
Last Post: mv8167
  What is a Method in QTP and how many types are method r there in QTP? vidyabr 1 4,321 07-28-2008, 02:14 PM
Last Post: surya_7mar

Forum Jump:


Users browsing this thread: 1 Guest(s)