Showing posts with label Excel Application QTP GetObject CreateObject Quit Excel Application Workbooks. Show all posts
Showing posts with label Excel Application QTP GetObject CreateObject Quit Excel Application Workbooks. Show all posts

Saturday, May 15, 2010

Quitting Excel Workbooks Using Getobject

Let’s consider that we have opened two excel workbooks using CreateObject. If you want to quit those two workbooks, try the below snippet.
Function fnc_CreateExcel
Set objNewExcel=CreateObject("Excel.Application")
objNewExcel.Visible=True
objNewExcel.Workbooks.Add
Set objNewExcel=Nothing
End Function

Call fnc_CreateExcel'Creating Book1
Call fnc_CreateExcel'Creating Book2

Call fnc_Quit_Excel("Book1")'Quitting Book 1
Call fnc_Quit_Excel("Book2")'Quitting Book 2

Function fnc_Quit_Excel(v_St_ExcelName)
Set objExcel=GetObject(v_St_ExcelName).Application'Getting Excel Object using Book name
objExcel.Quit
Set objExcel=Nothing
End Function