Micro Focus QTP (UFT) Forums
I want to Save the excel file without a save as window - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: I want to Save the excel file without a save as window (/Thread-I-want-to-Save-the-excel-file-without-a-save-as-window)



I want to Save the excel file without a save as window - cadari - 02-03-2010

Hi All,

Please let me know if there is something wrong with this code, I keep getting a pop up message to save the file and I am given an option to save as a different file and can't append an existing file. Any help is much appreciated:
Code:
sourcefile = [code]"\\..\..\Type_QTP.xls"
        Set xlApp = CreateObject("Excel.Application")
        Set xlWorkBook = xlApp.Workbooks.Open(sourcefile)
                Set xlWorkSheet = xlWorkBook.Worksheets("Sheet1")

           xlWorkSheet.Range("G2:G20") = "Some data"

    xlWorkBook.Save
    xlWorkBook.Close
    xlApp.Quit
    
    ' Destroy all the Objecte references
    Set xlApp = Nothing
    Set xlWorkBook = Nothing
    Set xlWorkSheet = Nothing


Thanks,
Mouli


RE: I want to Save the excel file without a save as window - sreekanth chilam - 02-03-2010

Hi,

Try as given below.

Code:
sourcefile = "\\..\..\Type_QTP.xls"
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Open(sourcefile)
xlApp.sheets("Sheet1").Select
xlApp.sheets("Sheet1").Range("G2:G20") = "Some data"
xlApp.ActiveWorkBook.Save
xlApp.Application.Quit
Set xlApp = Nothing



RE: I want to Save the excel file without a save as window - cadari - 02-03-2010

Excellent... Thanks Sreekanth...your solution worked....