Vous êtes sur la page 1sur 16

How can i check if a parameter exists in DataTable or not?

 The best way would be to use the below code:

code:
on error resume next
val=DataTable("ParamName",dtGlobalSheet)
if err.number<> 0 then
'Parameter does not exist
else
'Parameter exists
end if

How can i save the changes to my DataTable in the test itself?

 Well QTP does not allow anything for saving the run time changes to the actual data sheet. The
only work around is to share the

spreadsheet and then access it using the Excel COM Api's.

SMART Identification

Smart Identification is nothing but an algorithm used by QTP when it is not able to recognize one of the
object. A very generic example as per the

QTP manual would be, A photograph of a 8 year old girl and boy and QTP records identification
properties of that girl when she was 8, now when

both are 10 years old then QTP would not be able to recognize the girl. But there is something that is
still the same, that is there is only one girl in

the photograph. So it kind of PI (Programmed intelligence) not AI.

When should i use SMART Identification?

 Something that people don't think about too much. But the thing is that you should disable SI
while creating your test cases. So that you

are able to recognize the objects that are dynamic or inconsistent in their properties. When the
script has been created, the SI should be enabled,

so that the script does not fail in case of small changes. But the developer of the script should
always check for the test results to verify if the SI

feature was used to identify a object or not. Sometimes SI needs to be disabled for particular
objects in the OR, this is advisable when you use

SetTOProperty to change any of the TO properties of an object and especially ordinal identifiers
like index, location and creationtime.

Descriptive Programming

 Descriptive programming is nothing but a technique using which operations can be performed
on the AUT object which are not present in

the OR. For more details refer to http://bondofus.tripod.com/QTP/DP_in_QTP.doc (right click


and use save as...)
Recovery Scenarios

What is a Recovery Scenario?

 Recovery scenario gives you an option to take some action for recovering from a fatal error in
the test. The error could range in from

occasional to typical errors. Occasional error would be like "Out of paper" popup error while
printing something and typical errors would be like

"object is disabled" or "object not found". A test case have more then one scenario associated
with it and also have the priority or order in which it

should be checked.

What does a Recovery Scenario consists of?

 Trigger: Trigger is nothing but the cause for initiating the recovery scenario. It could be any
popup window, any test error, particular state

of an object or any application error.


 Action: Action defines what needs to be done if scenario has been triggered. It can consist of a
mouse/keyboard event, close application, call a

recovery function defined in library file or restart windows. You can have a series of all the
specified actions.
 Post-recovery operation: Basically defined what need to be done after the recovery action has
been taken. It could be to repeat the step, move

to next step etc....

When to use a Recovery Scenario and when to us on error resume next?

 Recovery scenarios are used when you cannot predict at what step the error can occur or when
you know that error won't occur in your

QTP script but could occur in the world outside QTP, again the example would be "out of paper",
as this error is caused by printer device driver. "On

error resume next" should be used when you know if an error is expected and dont want to
raise it, you may want to have different actions

depending upon the error that occurred. Use err.number & err.description to get more details
about the error.

Library Files or VBScript Files


How do we associate a library file with a test ?

 Library files are files containing normal VBScript code. The file can contain function, sub
procedure, classes etc.... You can also use executefile

function to include a file at run-time also. To associate a library file with your script go to Test-
>Settings... and add your library file to resources

tab.
When to associate a library file with a test and when to use execute file?

 When we associate a library file with the test, then all the functions within that library are
available to all the actions present in the test. But

when we use Executefile function to load a library file, then the function are available in the
action that called executefile. By associated a library to

a test we share variables across action (global variables basically), using association also makes
it possible to execute code as soon as the script

runs because while loading the script on startup QTP executes all the code on the global scope.
We can use executefile in a library file associated

with the test to load dynamic files and they will be available to all the actions in the test.

Add-ins

Test and Run-time Object


What is the difference between Test Objects and Run Time Objects ?

 Test objects are basic and generic objects that QTP recognize. Run time object means the actual
object to which a test object maps.

Can i change properties of a test object

 Yes. You can use SetTOProperty to change the test object properties. It is recommended that
you switch off the Smart Identification for the

object on which you use SetTOProperty function.

Can i change properties of a run time object?

 No (but Yes also). You can use GetROProperty("outerText") to get the outerText of a object but
there is no function like SetROProperty to

change this property. But you can use WebElement().object.outerText="Something" to change


the property.

Action & Functions


What is the difference between an Action and a function?

 Action is a thing specific to QTP while functions are a generic thing which is a feature of VB
Scripting. Action can have a object repository

associated with it while a function can't. A function is just lines of code with some/none
parameters and a single return value while an action can

have more than one output parameters.

Where to use function or action?

 Well answer depends on the scenario. If you want to use the OR feature then you have to go for
Action only. If the functionality is not about any
automation script i.e. a function like getting a string between to specific characters, now this is
something not specific to QTP and can be done on

pure VB Script, so this should be done in a function and not an action. Code specific to QTP can
also be put into an function using DP. Decision of

using function/action depends on what any one would be comfortable using in a given situation.

Checkpoint & Output value


What is checkpoint?

 Checkpoint is basically a point in the test which validates for truthfulness of a specific things in
the AUT. There are different types of

checkpoints depending on the type of data that needs to be tested in the AUT. It can be text,
image/bitmap, attributes, XML etc....

What's the difference between a checkpoint and output value?

 Checkpoint only checks for the specific attribute of an object in AUT while Output value can
output those attributes value to a column in data

table.

How can i check if a checkpoint passes or not?


code:
chk_PassFail = Browser(...).Page(...).WebEdit(...).Check (Checkpoint("Check1"))
if chk_PassFail then
MsgBox "Check Point passed"
else
MsgBox "Check Point failed"
end if
My test fails due to checkpoint failing, Can i validate a checkpoint without my test failing
due to checpoint failure?
code:
Reporter.Filter = rfDisableAll 'Disables all the reporting stuff
chk_PassFail = Browser(...).Page(...).WebEdit(...).Check (Checkpoint("Check1"))
Reporter.Filter = rfEnableAll 'Enable all the reporting stuff
if chk_PassFail then
MsgBox "Check Point passed"
else
MsgBox "Check Point failed"
end if
Environment
How can i import environment from a file on disk

 Environment.LoadFromFile "C:\Env.xml"

How can i check if a environment variable exist or not?

 When we use Environment("Param1").value then QTP expects the environment variable to be


already defined. But when we use

Environment.value("Param1") then QTP will create a new internal environment variable if it does
not exists already. So to be sure that variable exist

in the environment try using Environment("Param1").value.


How to connect to a database?
code:
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DRIVER={Microsoft ODBC for Oracle};UID=<UID>;PWD=<PWD>"
objRecordset.CursorLocation = adUseClient
objRecordset.CursorType = adopenstatic
objRecordset.LockType = adlockoptimistic
ObjRecordset.Source="select field1,field2 from testTable"
ObjRecordset.ActiveConnection=ObjConnection
ObjRecordset.Open 'This will execute your Query
If ObjRecordset.recordcount>0 then
Field1 = ObjRecordset("Field1").Value
Field2 = ObjRecordset("Field2").Value
End if
XML in QTP

 Well i am not explaining what to do in case of XMLs, but i am pasting two post that might help...
http://www.qaforums.com/ultimatebb.php?ubb=get_topic;f=20;t=004193#000004
http://www.qaforums.com/ultimatebb.php?ubb=get_topic;f=20;t=005111#000002

Function :

Function PressKeyboardEnterButton(sWindowTitle)
Set WshShell = CreateObject("WScript.Shell")
WshShell.AppActivate sWindowTitle
wait(1)
WshShell.SendKeys "{ENTER}"
wait(3)
End Function

This function verifies that supplied database, uid and pwd are valid or not.
Code:

Function VerifyDatabaseNameUidPwd(sDatabaseName,sUID,sPWD)

'Create the connection string:


strConn="DRIVER={Microsoft ODBC for Oracle};SERVER=" & sDatabaseName & ";User ID="
& sUID & ";Password=" & sPWD & " ;"
'Establish the connection:
Set oConn = CreateObject("ADODB.Connection")
'Server-side cursor
oConn.CursorLocation = 2
On Error Resume Next
err.clear
oConn.Open strConn
if err.number <> 0 then
if Instr(Err.Description,"TNS:could not resolve service name") > 0 then
Call CreateUserDefineResultFile("Fail=> " & Environment("TestName"))

Reporter.ReportEvent micFail,"Either database is down or Database Name is


incorrect", sDatabaseName
end if
if Instr(Err.Description,"invalid") > 0 then
Call CreateUserDefineResultFile("Fail=> " & Environment("TestName"))

Reporter.ReportEvent micFail,"Invalid Database UserId/Password", sUID &


"/" & sPWD
end if

Set strConn=nothing
Set oConn=nothing
ExitAction(0)
end if
Set strConn=nothing
Set oConn=nothing
End Function

How to call this function?


set vObject=Browser().Page().WebList()
sItem="India"
call VerifyItemExistsInWebList(vObject,sItem)

Code:

Function VerifyItemExistsInWebList(vObject,sItem)
bFound=False
iTotalItem=vObject.GetROProperty("Items Count")
For i = 1 to iTotalItem
if vObject.GetItem(i) = sItem then
bFound=True
Exit for
end if
next

If bFound=False Then
Reporter.ReportEvent micFail,"Item NOT found:",sItem
VerifyItemExistsInWebList="False"
End If
End Function

---- This function is to get Webtable index -----------

Function GetQTPTableIndex(BrowserObj, TableObj)


On Error Resume Next
domIndex = TableObj.GetROProperty("source_index")
Set allTables = BrowserObj.object.document.getElementsByTagName("TABLE")
Dim i
i=0
For Each table In allTables
If table.sourceIndex=domIndex Then
GetQTPTableIndex=i
Exit For
End If
i=i+1
Next
Set allTables = Nothing ' Clear object from memory.
End Function

Set QAFBROWSER = Browser("QA Forums: Problem in")


Set QAFPAGE = Browser("QA Forums: Problem in").Page("QA Forums: Problem in")
msgbox GetQTPTableIndex(QAFBROWSER, QAFPAGE.WebTable("InnerText:=Author.*","index:=0"))

Function :
Return Value: Boolean
' True = String split successfully
' False = Unable to split string at designated position
'
' Input Parameters: sInputString - string to be split
' iSplitPoint - number of characters to be splitted from the beginning of the sInputString
'
' Output Parameters: sFirstPortion - Substring of the original string
' prior to the split point
' sRemainingPortion - Remaining substing of the
' original string
'
' Note: Returns false if sInputString is empty or if iSplitPoint < 0.
Function SplitStringByIndex(ByVal sInputString, ByVal iSplitPoint, _
ByRef sFirstPortion, ByRef sRemainingPortion)

Dim bReturnValue, iInputStringLen


bReturnValue = False

iInputStringLen = Len(sInputString)

If iSplitPoint > 0 And iInputStringLen > 0 Then


If iSplitPoint > iInputStringLen Then
sFirstPortion = sInputString
sRemainingPortion = ""
ElseIf iSplitPoint = 1 Then
sFirstPortion = ""
sRemainingPortion = sInputString
Else
sFirstPortion = Left(sInputString, iSplitPoint)
sRemainingPortion = Right(sInputString, (iInputStringLen - iSplitPoint))
End If
bReturnValue = True
End If

SplitStringByIndex = bReturnValue
End Function 'SplitStringByIndex
'
'
Using:
If (SplitStringByIndex("1234", 2, sFirstPortion, sRemainingPortion)) Then
MsgBox sFirstPortion
MsgBox sRemainingPortion
Else
MsgBox "Unable to split string at designated position"
End If
'
'
Using in your case:
If (SplitStringByIndex("23345645", 2, sFirstPortion, sRemainingPortion)) Then
YourVariableForComparison = sFirstPortion & “-” & sRemainingPortion
Else
MsgBox "Unable to parse innitial string"
End If

I executed 15 QTP scripts via Test Batch Runner.


Now I had to OPEN each test result file for 15 scripts to see pass or fail status.

Solution
Call below functions at the end of the each script.
Code:
________________________________________

sAppResultFilePath="C:\QTP\Test1\Res1\Report\Results.xml"
sFileName="Test-Result.txt"
sFilePath="C:\Temp\"

Call
CreateUserDefineResultFile(sFileName,sFilePath,GetPassFailStatusFromResultsXML(sAppResultFilePath)
)

Function GetPassFailStatusFromResultsXML(sAppResultFilePath)
Set doc = XMLUtil.CreateXML()
doc.LoadFile sAppResultFilePath

Set oDoc = doc.GetRootElement.ChildElements.ItemByName("Doc")


Set oDocSummary= oDoc.ChildElements.ItemByName("Summary")

Set SummaryAttribs = oDocSummary.Attributes()


Set FailedCount = SummaryAttribs.ItemByName("failed")
Set PassedCount = SummaryAttribs.ItemByName("passed")

If FailedCount.Value > 0 Then


GetPassFailStatusFromResultsXML= "Fail: " & Environment("TestName")
else
GetPassFailStatusFromResultsXML= "Pass: " & Environment("TestName")
End If
End Function

Function CreateUserDefineResultFile(sFileName,sFilePath,sTextToWrite)

Dim objFSO, objFolder, objShell, objTextFile, objFile


' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Check that the sFilePath folder exists
If objFSO.FolderExists(sFilePath) Then
Set objFolder = objFSO.GetFolder(sFilePath)
Else
Set objFolder = objFSO.CreateFolder(sFilePath)
End If

If objFSO.FileExists(sFilePath & sFileName) Then


Set objFolder = objFSO.GetFolder(sFilePath)
Else
Set objFile = objFSO.CreateTextFile(sFilePath & sFileName)
End If

set objFile = nothing


set objFolder = nothing
' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 8

Set objTextFile = objFSO.OpenTextFile _


(sFilePath & sFileName, ForAppending, True)

' Writes sTextToWrite every time you run this VBScript


objTextFile.WriteLine(sTextToWrite)
objTextFile.Close
End Function

public sub writelog(scode, smessage, bpopup)


'===============================================================
=====================
' Purpose: Writes log information to logfile
' Inputs: scode: String - string to put in the first column
' smessage: String - contains the message text
' bpopup: boolean - if TRUE then show message in popup
'===============================================================
=====================

dim fso, fl, flname, fldr

Set fso = CreateObject("Scripting.FileSystemObject")

if not fso.FolderExists(fso.GetAbsolutePathName(".") & "\log") then


set fldr = fso.CreateFolder(fso.GetAbsolutePathName(".") & "\log")
end if

flname = fso.GetAbsolutePathName(".") & "\log\" & year(date) & left(100 + month(date),2) &
left(100+day(date),2) & ".log"
Set fl = fso.OpenTextFile(flname, 8, True)

on error resume next


fl.write date & ", " & time & ", " & scode & ", " & smessage & vbcrlf
on error goto 0
fl.close
set fso = nothing

if bpopup then msgbox(date & ", " & time & ", " & scode & ", " & smessage)
End sub

'========== How to Call it ==========

writelog "TEST", "This is the message to output to the logfile", FALSE

writelog "TEST", "This is the message to output to the logfile and popup", TRUE

A demo of excel read and write code.


Public sFileName
Public Row
Public sData
Public notfound
Public iNoError
Public sCurrentProc
Public sWinDir
Public lResult
Public strMsgText
Public iColNum
Public sTestData
Public ColHead
Public rows
Public Columns
Public Value
Public FoundVal
Public oSearchRegion
Public oSearchResult
Public FirstCol
Public sFieldName
Public vSheet
Public TotalRows
Public iRow
Public fso
Public objWorkBook
Public objWorkSheet

'Instructions
'1. Create a folder C:\Data
'2. Create an Excel file Client.xls (make this a shared workbook)
'Name the first sheet Client_Creation
'4. Run this script and view the created file.

'#### This block sets up the Data File to use


'#### You will need to create the file and the path
sFileName = "C:\Data\Client.xls" 'Set the sFilename value
Row = 2 'Set the start Row
vSheet = "Client_Creation" 'Set the Start Sheet

'### These Input boxes are to demonstrate assigning the string values. These values could come from
a GET Text function.
strClientType = InputBox("Client Type")
strGivenName = InputBox("Enter your Given Name")
strSurname = InputBox("Enter your Surname")

'#### This line writes Data to sFileName. It will write data to a Column Called "ClientTypeS" it will
write the value strClientType
'#### On the Sheet called "Client_Creation". If the Column ClientTypeS doesnt exist it will be created.
If the sheet Client_Creation
'#### doesnt exist it will be created
Call WriteExcelDataSingle(sFileName, 2, "ClientTypeS", strClientType,"Client_Creation")
Call WriteExcelDataSingle(sFileName, 2, "Surname", strSurname,"Client_Creation")
Call WriteExcelDataSingle(sFileName, 2, "Given_Name1", strGivenName,"Client_Creation")

'#### This code will read the values created by the code above
Call OpenExcel(sFileName, vSheet)
strClientType1 = ReadExcelDataSingle(sFileName,Row,"ClientTypeS",vSheet)
strSurname1 = ReadExcelDataSingle(sFileName,Row,"Surname",vSheet)
strGivenName1 = ReadExcelDataSingle(sFileName,Row,"Given_Name1",vSheet)
Call CloseExcel(sFileName)

'#### Just to show the values


msgbox strClientType1 & " " & strGivenName1 & " " & strSurname1

'###############################################################
###############################
'# The code below will read across columns
'#
'#
'###############################################################
###############################

iRow = 2
ControlVar_1 = 1
Call OpenExcel(sFileName, "Client_Creation") 'Open Data File for read
'TestVar = ReadExcelDataSingle(sFileName,iRow,ControlVar,"Client_Creation")

Do while ControlVar_1 < 6


' Work along the Top Row EXCL_PERILS
strInputEXCLPRLS = ReadExcelDataSingle(sFileName,iRow,"EXCL_PERILS_" &
ControlVar_1,"Client_Creation")
Call Popup (strInputEXCLPRLS) 'The Popup will display each value in order across the
sheet
ControlVar_1 = ControlVar_1 + 1
loop

Call CloseExcel(sFileName) 'Close Data File

'******************************************************************************
'* ReadExcelDataSingle Developed by: Steve Morrin
'*
'*
'* Converted for QTP use by: Ian Fraser 01 Dec 2005
'* 20/06/03 Steve Morrin Add dictionery
'******************************************************************************
'* Example
'* strTest = ReadExcelDataSingle(sFileName,2,"PolicyNoHom","Global")
'*
Public Function ReadExcelDataSingle(sFileName,iRow,sFieldName,vSheet)

Dim sData
Dim iNoError
Dim sCurrentProc
Dim sWinDir
Dim lResult
Dim strMsgText
Dim iColNum
Dim sTestData
Dim ColHead

'Count Columns
ColCount = objWorkSheet.UsedRange.columns.count

set oSearchRegion = objWorkSheet.Range(objWorkSheet.cells(1,1),objWorkSheet.cells(1, ColCount


))
notfound = ""
with oSearchRegion
set oSearchResult = .Find(sFieldName)
if not oSearchResult is nothing then
iColNum = oSearchResult.column
FirstCol = iColNum
FoundVal = objWorkSheet.Rows(1).Columns(iColNum).Value
if sFieldName <> FoundVal then
do
set oSearchResult = .Findnext(oSearchResult)
iColNum = oSearchResult.column
FoundVal = objWorkSheet.Rows(1).Columns(iColNum).Value
loop while FirstCol <> iColNum and sFieldName <> FoundVal
if sFieldName <> FoundVal then notfound = "Y"
end if
else
notfound = "Y"
end if
End With

'Retrieve the value from the cell


sData = ""
if notfound = "" then
sData =objWorkSheet.rows(iRow).Columns(iColNum).Value
end if
sData = Trim(sData)

ReadExcelDataSingle = sData

End Function
'******************************************************************************
'******************************************************************************
'* OpenExcel
'*
'* Open XL ready for read
'******************************************************************************
Public sub OpenExcel(sFileName, vSheet)

Set fso = CreateObject("Excel.Application")

Set objExcel = fso

'objWorkBook = objExcel.Workbooks.Open (sFileName)


Set objWorkBook = objExcel.Workbooks.Open (sFileName)

'See if a sheet was referenced in the call. If not, default to the first sheet
If vSheet = "" Then
vSheet = 1
End If

'Set up a reference to the sheet in the workbook


Set objWorkSheet = objWorkBook.WorkSheets(vSheet)

'Create a new sheet if required


'On Error Resume

if objWorkBook.WorkSheets(vSheet) is nothing then

objWorkBook.WorkSheets.Add
'objWorkBook.WorkSheets.Select
newName = objWorkBook.ActiveSheet.Name

objWorkBook.WorkSheets(newName).Name = vSheet
'Save the changes
objWorkBook.Save
end if

'Set up a reference to the sheet in the workbook


Set objWorkSheet = objWorkBook.WorkSheets(vSheet)

End sub
'******************************************************************************
'******************************************************************************
'* CloseExcel
'*
'* Close XL
'******************************************************************************
Public sub CloseExcel(sFileName)

Set objExcel = fso


Set objWorkBook = objExcel.Workbooks.Open (sFileName)

'Save the changes


objWorkBook.Save
objWorkBook.Close

'Clear all the references to the objects


Set objWorkBook = Nothing
objExcel.Quit
Set objExcel = Nothing

'reset the distionary object


Set oDict = Nothing
sPersistXL = "" 'Global var
End sub
'******************************************************************************
'* WriteExcelDataSingle Developed by: Steve Morrin
'*
'* Converted for QTP use by: Ian Fraser 01 Dec 2005
'* 20/06/03 - Steve Morrin - Add dictionary.
'******************************************************************************
'* Example
'* Call WriteExcelDataSingle(sFileName, 2, "PolicyNoHom", strOne,"Global")
'*
'Function WriteExcelDataSingle(sFileName, iRow, sFieldName, vValue,vSheet)
Public Function WriteExcelDataSingle(sFileName, iRow, sFieldName, vValue,vSheet)

'Dimension the needed variables


Dim iNoError
Dim sCurrentProc
Dim sWinDir
Dim lResult
Dim strMsgText
Dim iColNum
Dim sTestData
Dim NewVal

'Deal with the optional parameters


If vSheet = "" Then
vSheet = 1
End If

Set fso = CreateObject("Excel.Application")

'Open up Excel
If fso Is Nothing Then
Set fso = CreateObject("Excel.Application")
End If

Set objExcel = fso

'Open the workbook


If sFileName = "" Then
set oDict = Nothing ' do not use dictionery for new sheet
Set objWorkBook = objExcel.Workbooks.Add
objWorkBook.SaveAs (sFileName)
Else
Set objWorkBook = objExcel.Workbooks.Open(sFileName)
End If
'Create a new sheet if required
On Error Resume Next
if objWorkBook.WorkSheets(vSheet) is nothing then
set oDict = Nothing ' do not use dictionery for new sheet
objWorkBook.WorkSheets.Add
newName = objWorkBook.ActiveSheet.Name

objWorkBook.WorkSheets(newName).Name = vSheet
'Save the changes
objWorkBook.Save
end if

'Set up a reference to the sheet in the workbook


Set objWorkSheet = objWorkBook.WorkSheets(vSheet)

'Count Columns
ColCount = objWorkSheet.UsedRange.columns.count

set oSearchRegion = objWorkSheet.Range(objWorkSheet.cells(1,1),objWorkSheet.cells(1,


ColCount ))
notfound = ""
with oSearchRegion
set oSearchResult = .Find(sFieldName)
if not oSearchResult is nothing then
iColNum = oSearchResult.column
FirstCol = iColNum
FoundVal = objWorkSheet.Rows(1).Columns(iColNum).Value
if sFieldName <> FoundVal then
do
set oSearchResult = .Findnext(oSearchResult)
iColNum = oSearchResult.column
FoundVal = objWorkSheet.Rows(1).Columns(iColNum).Value
loop while FirstCol <> iColNum and sFieldName <> FoundVal
if sFieldName <> FoundVal then notfound = "Y"
end if
else
notfound = "Y"
end if
End With

if notfound = "Y" then


iColNum = ColCount + 1
if iColNum = 2 then 'check for empty col 1 on new sheet
NewVal = objWorkSheet.Rows(1).Columns(1).Value
if NewVal = "" then iColNum = 1
end if
'Write new heading
objWorkSheet.Rows(1).Columns(iColNum).Value = sFieldName
end if

'write data to XL
objWorkSheet.Rows(iRow).Columns(iColNum).Value = vValue

'Save the changes


objWorkBook.Save

'At this point, everything that follows is cleanup. Since we want it to


'occur even if an error occurred, we'll ignore any further errors generated
'in this function

On Error Resume Next


if sPersistXL = "" then
'Close the workbook
objWorkBook.Close

'Clear all the references to the objects


Set objWorkBook = Nothing
Set objWorkSheet = Nothing

objExcel.Quit
set objExcel = nothing
end if
End Function
'###############################################################
#############################
'###############################################################
#############################
'# Function to look up a stored check point and when detected optionaly provide for reposition.
'* Converted for QTP use by: Ian Fraser 14 Dec 2005
'* 20/06/03 Steve Morrin
'* Associated Scripts
'* OpenExcel.vbs
'*CloseExcel.vbs
'*GlobalVars.vbs
'###############################################################
#############################
'#Set Start Row (Check Re-Start Value in DataTable)
'#ChkCol = "Re-Start"
'#Row = GetCheckpoint(sFileName ,ChkCol, vSheet)
'###############################################################
#############################
Public Function GetCheckpoint (sFileName ,ChkCol, vSheet)
if vSheet = "" then vSheet = 1

'look in XL to see if check point exists


Call OpenExcel(sFileName, vSheet)
sStartRow = ReadExcelDataSingle(sFileName,2,ChkCol, vSheet) ' in global not included here
Call CloseExcel(sFileName)

if sStartRow = "" or sStartRow = "2" then


sStartRow = "2" 'All XLs have header rows so data starts in row.
else
sAdjustedStart = InputBox("Restart dectected Press OK to accept or type new start
point. Include Header Row", _
"Check Point Restart", sStartRow)
do while sAdjustedStart <> sStartRow
sStartRow = sAdjustedStart
sAdjustedStart = InputBox("Confirm Start row","Restart Confirmation",
sAdjustedStart )
loop
end if
if sStartRow = "0" or sStartRow = "1" then sStartRow = "2" ' all data starts in row 2
GetCheckpoint = (sStartRow)
Call CloseExcel(sFileName)
End Function

'###############################################################
############
'******************************************************************************
'Used to end any remaining Excel processes
Public Sub KillExcel ()
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colProcesses = objWMIService.ExecQuery ("Select * from Win32_Process Where Name =


'Excel.exe'")
For Each objProcess in colProcesses
objProcess.Terminate()
Next
End Sub
'******************************************************************************
'******************************************************************************
Public Sub Popup (strInValue)
Set msg=CreateObject("Wscript.Shell")
for i=1 to 9
msg.Popup strInValue & " - " & 8-i+1 & " second(s)", 1
next
End Sub
'******************************************************************************

Vous aimerez peut-être aussi