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

2 comments:

  1. Can the Excel WB be opened manually or by a UFT / QTP script and then a script be used to .quit the open WB?

    ReplyDelete
  2. Can the Excel WB be opened manually or by a UFT / QTP script and then a script be used to .quit the open WB?

    ReplyDelete